在 2.0.0 版中,声网优化了声网 Classroom SDK 的内部架构,重新设计了 Edu Context API。
本节列出 2.0.0 与 1.1.5 在 Edu Context API 上的主要变动。
移除 AgoraEduMessageContext
和 AgoraEduMessageHandler
,由 AgoraWidgets
库中的 AgoraRtmIMWidget
代替。
移除 AgoraEduWhiteBoardContext
、AgoraEduWhiteBoardHandler
、AgoraEduWhiteBoardToolContext
、 AgoraEduWhiteBoardPageControlContext
、AgoraEduWhiteBoardPageControlHandler
,
由 AgoraWidgets
库中的 AgoraWhiteBoardWidget
代替。
移除 AgoraEduDeviceContext
和 AgoraEduDeviceHandler
,该类提供的方法和回调由 AgoraEduMediaContext
和 AgoraEduMediaHandler
代替,具体如下:
setCameraDeviceEnable
、setMicDeviceEnable
、setSpeakerDeviceEnable
由 AgoraEduMediaContext
中的 openLocalDevice
和 closeLocalDevice
代替。switchCameraFacing
由 AgoraEduMediaContext
中的openLocalDevice
代替。onCameraDeviceEnableChanged
、onCameraDeviceFacingChanged
、onMicDeviceEnableChanged
、onSpeakerDeviceEnableChanged
由 AgoraEduMediaHandler
中的 onLocalDeviceStateUpdated
代替。移除 AgoraEduHandsUpContext
和 AgoraEduHandsUpHandler
,该类提供的方法和回调由 AgoraEduUserContext
和 AgoraEduUserHandler
代替,具体如下:
updateHandsUpState
由 AgoraEduUserContext
中的 handsWave
和 handsDown
代替。onHandsUpState
由 AgoraEduUserHandler
中的 onUserHandsWave
和 onUserHandsDown
代替。onHandsUpEnable
由 AgoraEduUserHandler
中的 onUserHandsWaveEnable
代替。openCamera
更名为 openLocalDevice
。closeCamera
更名为 closeLocalDevice
。startPreview
更名为 startRenderVideo
。stopPreview
更名为 stopRenderVideo
。openMicrophone
更名为 openLocalDevice
。closeMicrophone
更名为 closeLocalDevice
。renderRemoteView
更名为 startRenderVideo
。publishStream
。unpublishStream
。joinClassroom
更名为 joinRoom
。updateFlexRoomProperties
更名为 updateRoomProperties
。uploadLog
和 onUploadLogSuccess
,由 AgoraEduMonitorContext
中的 uploadLog
代替。registerEventHandler
更名为 registerRoomEventHandler
。onShowErrorInfo
。onClassroomJoined
更名为 onRoomJoinedSuccess
。onFlexRoomPropertiesInitialize
更名为 RoomContext.getRoomProperties
。onFlexRoomPropertiesChanged
,由 onRoomPropertiesUpdated
和 onRoomPropertiesDeleted
代替。onClassroomName
,由 AgoraEduRoomContext
中的getRoomInfo
代替。onClassroomState
,由 onClassStateUpdated
和 onRoomClosed
代替。onClassTimeInfo
由 AgoraEduRoomContext
中的 getRoomInfo
代替。onNetworkQuality
由 AgoraEduMonitorHandler
中的 onLocalNetworkQualityUpdated
代替。onConnectionState
由 AgoraEduMonitorHandler
中的 onLocalConnectionUpdated
代替。AgoraEduScreenShareContext
和AgoraEduScreenShareHandler
,由 AgoraEduStreamContext
代替。当 AgoraEduContextStreamInfo
里有 videoSourceType
为 screen
时,可以判断为屏幕共享视频流。AgoraEduScreenShareHandler
。 AgoraEduStreamContext
代替。onUpdateScreenShareState
由 AgoraEduStreamHandler
中的onStreamJoined
、onStreamLeft
、onStreamUpdate
代替。updateFlexUserProperties
更名为 updateUserProperties
registerEventHandler
更名为 registerUserEventHandler
onUpdateUserList
,由 onRemoteUserJoined
、 onRemoteUserLeft
、onUserUpdated
代替。onUpdateCoHostList
,由 onCoHostUserListAdded
、 onCoHostUserListRemoved
代替。onKickOut
更名为 onLocalUserKickOut
。onUpdateAudioVolumeIndication
, 由 AgoraEduMediaHandler
中的 onVolumeUpdated
代替。onShowUserReward
更名为 onUserRewarded
。onFlexUserPropertiesChanged
,由 onUserPropertiesUpdated
、onUserPropertiesDeleted
代替。onStreamUpdated
,由 AgoraEduStreamHandler
中的 onStreamUpdated
代替。如果你在 1.1.5 之前版本中修改了灵动课堂的默认 UI,需参考以下步骤从 1.1.5 之前的版本升级至 1.1.5:
根据集成灵动课堂文档中的步骤将 1.1.5 集成至你的项目中。
用原先 AgoraEduSDK/Modules/AgoraUIEduAppViews/AgoraUIEduAppView 目录下的文件替换 SDKs/AgoraEduUI 目录下的文件,具体如下:
AgoraUIManager.swift
改名为 AgoraEduUI.swift
,将AgoraUIManager
类改名为 AgoraEduUI
。AgoraEduUI.swift
文件在 AgoraEduUI.swift
中,进行以下修改:
将 AgoraEduContextAppType
更名为 AgoraEduContextRoomType
。
将 var chat: AgoraEduWidget
改为 var chat: AgoraBaseWidget
。
参考下图,添加以下代码新增 initWidgets
方法。
func initWidgets() {
guard let widgetInfos = contextPool.widget.getWidgetInfos() else {
return
}
for info in widgetInfos {
switch info.widgetId {
case "AgoraChatWidget":
info.properties = ["contextPool": contextPool]
let chat = contextPool.widget.create(with: info)
chat.addMessageObserver(self)
let hasConversation = (viewType == .oneToOne ? 0 : 1)
if let message = ["hasConversation": hasConversation].jsonString() {
chat.widgetDidReceiveMessage(message)
}
self.chat = chat
default:
break
}
}
}
用原先 AgoraEduSDK/Modules/AgraUIEduBaseViews 目录下的文件替换 SDKs/Modules/AgraUIEduBaseViews 目录下的文件,具体如下:
AgoraChatWidget.swift
文件在 AgoraChatWidget.swift
文件中进行以下操作:
将初始化方法更改为下面的新的初始化方法:
public required init(widgetId: String,
contextPool: AgoraEduContextPool,
properties: [AnyHashable : Any]?) {
super.init(widgetId: widgetId,
contextPool: contextPool,
properties: properties)
initViews()
initLayout()
initData()
}
增加 AgoraEduMessageContext
属性:
private weak var context: AgoraEduMessageContext?
public required override init(widgetId: String,
properties: [AnyHashable: Any]?) {
super.init(widgetId: widgetId,
properties: properties)
initViews()
initLayout()
if let contextPool = properties?["contextPool"] as? AgoraEduContextPool {
context = contextPool.chat
initData()
}
}