UNPKG

cloudhub-electron-sdk

Version:

cloudhub-electron-sdk

188 lines (187 loc) 11.3 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const utils_1 = __importDefault(require("../helpers/utils")); const Renderer_1 = require("../Renderer"); const log_1 = __importDefault(require("../helpers/log")); const Stream_1 = __importDefault(require("../rtcEngine/Stream")); class MessageController { constructor(rtcChannel, room) { this.rtcChannel = rtcChannel; this.room = room; } apiCallback() { this.rtcChannel.onEvent('connectionStateChanged', (state) => { log_1.default.info(`onConnectionStateChanged state:${state} RtcChannelEvent: ${this.rtcChannel.RtcChannelEvent}`); this.rtcChannel.RtcChannelEvent.trigger('onConnectionStateChanged', { state }); }); this.rtcChannel.onEvent('connectionlost', () => { log_1.default.info('onConnectionLost'); this.rtcChannel.RtcChannelEvent.trigger('onConnectionLost'); }); this.rtcChannel.onEvent('requesttoken', () => { log_1.default.info('onRequestToken'); this.rtcChannel.RtcChannelEvent.trigger('onRequestToken'); }); this.rtcChannel.onEvent('tokenPrivilegeWillExpire', (token) => { log_1.default.info('onTokenPrivilegeWillExpire', token); this.rtcChannel.RtcChannelEvent.trigger('onTokenPrivilegeWillExpire', { token }); }); this.rtcChannel.onEvent('clientrolechanged', (state) => { log_1.default.info(`onClientRoleChanged state:${state}`); this.rtcChannel.RtcChannelEvent.trigger('onClientRoleChanged', { state }); }); this.rtcChannel.onEvent('firstremotevideoframe', (uid, mediaType, width, height) => { log_1.default.info(`onFirstRemoteVideoFrame uid:${uid} mediaType:${mediaType} width:${width} height:${height}`); this.rtcChannel.RtcChannelEvent.trigger('onFirstRemoteVideoFrame', { uid, mediaType, width, height }); }); this.rtcChannel.onEvent('firstremoteaudioframe', (uid) => { log_1.default.info(`onFirstRemoteAudioFrame uid:${uid}`); this.rtcChannel.RtcChannelEvent.trigger('onFirstRemoteAudioFrame', { uid }); }); this.rtcChannel.onEvent('error', (err, msg) => { log_1.default.info(`onError err:${err} msg:${msg}`); this.rtcChannel.RtcChannelEvent.trigger('onError', { err, msg }); }); this.rtcChannel.onEvent('chatMsg', (fromId, textMsg, extraData) => { log_1.default.info(`onChatMsg fromId:${fromId} textMsg:${textMsg} extraData:${extraData}`); this.rtcChannel.RtcChannelEvent.trigger('onChatMsg', { fromId, textMsg, extraData: utils_1.default.strToJson(extraData) }); }); this.rtcChannel.onEvent('pubMsg', (msgId, msgName, fromId, toId, data, associatedUserId, associatedMsgId, ts, extraData, isHistory, seq) => { log_1.default.info(`onPubMsg msgId:${msgId} msgName:${msgName} fromId:${fromId} toId:${toId} data:${data} associatedUserId:${associatedUserId} associatedMsgId:${associatedMsgId} ts:${ts} extraData:${extraData} isHistory:${isHistory} seq:${seq}`); this.rtcChannel.RtcChannelEvent.trigger('onPubMsg', { isHistory, data: utils_1.default.strToJson(data), extraData: utils_1.default.strToJson(extraData), associatedUserId, associatedMsgId, fromId, msgId, msgName, toId, ts, seq }); }); this.rtcChannel.onEvent('delMsg', (msgId, msgName, fromId, toId, associatedUserId, associatedMsgId, ts, data, seq) => { log_1.default.info(`onDelMsg msgId:${msgId} msgName:${msgName} fromId:${fromId} toId:${toId} associatedUserId:${associatedUserId} associatedMsgId:${associatedMsgId} ts:${ts} data:${data} seq:${seq}`); this.rtcChannel.RtcChannelEvent.trigger('onDelMsg', { msgId, msgName, fromId, toId, associatedUserId, associatedMsgId, ts, data: utils_1.default.strToJson(data), seq }); }); this.rtcChannel.onEvent('setProperties', (userId, fromId, properties) => { log_1.default.info(`onSetProperty userId:${userId} fromId:${fromId} properties:${properties}`); this.rtcChannel.RtcChannelEvent.trigger('onSetProperty', { userId, fromId, properties: utils_1.default.strToJson(properties) }); }); this.rtcChannel.onEvent('localUserEvicted', (reason) => { log_1.default.info(`onLocalUserEvicted reason:${reason}`); this.rtcChannel.RtcChannelEvent.trigger('onLocalUserEvicted', { reason }); }); this.rtcChannel.onEvent('joinChannelSuccess', (uid, elapsed) => { log_1.default.info(`onJoinChannel uid:${uid} elapsed:${elapsed}`); this.room.setMyself({ uid }); this.rtcChannel.RtcChannelEvent.trigger('onJoinChannel', { uid, elapsed }); }); this.rtcChannel.onEvent('rejoinChannelSuccess', (uid, elapsed) => { log_1.default.info(`onRejoinChannel uid:${uid} elapsed:${elapsed}`); this.rtcChannel.RtcChannelEvent.trigger('onRejoinChannel', { uid, elapsed }); }); this.rtcChannel.onEvent('recordMsg', (data) => { const { currTs, pauseDuration, recordDuration, recordState, startTs } = utils_1.default.strToJson(data); log_1.default.info(`onRecordMsg currTs:${currTs} pauseDuration:${pauseDuration} recordDuration:${recordDuration} recordState:${recordState} startTs:${startTs}`); this.rtcChannel.RtcChannelEvent.trigger('onRecordMsg', { currTs, pauseDuration, recordDuration, recordState, startTs }); }); this.rtcChannel.onEvent('leavechannel', (states) => { log_1.default.info(`onLeaveChannel states:${states}`); this.rtcChannel.RtcChannelEvent.trigger('onLeaveChannel', { states }); }); this.rtcChannel.onEvent('rtcstats', (stats) => { this.rtcChannel.RtcChannelEvent.trigger('onRtcStats', { stats }); }); this.rtcChannel.onEvent('networkquality', (uid, txQuality, rxQuality) => { this.rtcChannel.RtcChannelEvent.trigger('onNetworkQuality', { uid, txQuality, rxQuality }); }); this.rtcChannel.onEvent('userjoined', (uid, properties, isHistory, fromChannelId) => { log_1.default.info(`onUserJoined uid:${uid} properties:${properties} isHistory:${isHistory}`); this.rtcChannel.RtcChannelEvent.trigger('onUserJoined', { isHistory, uid, properties: utils_1.default.strToJson(properties), fromChannelId }); }); this.rtcChannel.onEvent('useroffline', (uid) => { log_1.default.info(`onUserOffline uid:${uid}`); this.rtcChannel.RtcChannelEvent.trigger('onUserLeaved', { uid }); }); this.rtcChannel.onEvent('remoteVideoStateChanged', (uid, mediaType, streamId, state, reason, streamInfo) => { log_1.default.info(`onRemoteVideoStateChanged uid:${uid} mediaType:${mediaType} streamId:${streamId} state:${state} reason:${reason} streamInfo:${streamInfo}`); let stream = Stream_1.default.getStream(streamId); if (state === 0 && reason !== 5 && stream) { Stream_1.default.delStream(streamId); } if (state === 1 && !stream) { Stream_1.default.setStream(streamId, { renderer: new Renderer_1.GlRenderer(), streamId, isLocal: false, viewId: '', cid: this.rtcChannel.cid }); } this.rtcChannel.RtcChannelEvent.trigger('onRemoteVideoStateChanged', { uid, state, mediaType, reason, streamId, streamInfo: utils_1.default.strToJson(streamInfo), }); }); this.rtcChannel.onEvent('remoteAudioStateChanged', (uid, state, reason) => { log_1.default.info(`onRemoteAudioStateChanged uid:${uid} state:${state} reason:${reason}`); this.rtcChannel.RtcChannelEvent.trigger('onRemoteAudioStateChanged', { uid, state, reason, }); }); this.rtcChannel.onEvent('localMovieStateChanged', (mediafile, state, errCode) => { log_1.default.info(`onLocalMovieStateChanged mediafile:${mediafile} state:${state} errCode:${errCode}`); this.rtcChannel.RtcChannelEvent.trigger('onLocalMovieStateChanged', { mediafile, state, errCode, }); }); this.rtcChannel.onEvent('audiovolumeindication', (speakers, speakerNumber, totalVolume) => { this.rtcChannel.RtcChannelEvent.trigger('onAudioVolumeIndication', { speakers, speakerNumber, totalVolume }); }); this.rtcChannel.onEvent('movieProgress', (mediaFile, pos, total) => { this.rtcChannel.RtcChannelEvent.trigger('onMovieProgress', { mediafile: mediaFile, pos, total }); }); this.rtcChannel.onEvent('remotevideostats', (stats) => { log_1.default.info(`onRemoteVideoStats stats:`, stats); this.rtcChannel.RtcChannelEvent.trigger('onRemoteVideoStats', { stats }); }); this.rtcChannel.onEvent('remoteaudiostats', (stats) => { log_1.default.info(`onRemoteAudioStats stats:`, stats); this.rtcChannel.RtcChannelEvent.trigger('onRemoteAudioStats', { stats }); }); this.rtcChannel.onEvent('sharedWindowClosed', (windowId) => { this.rtcChannel.RtcChannelEvent.trigger('onSharedWindowClosed', { windowId }); }); this.rtcChannel.onEvent('channelMediaRelayStateChanged', (targetChannelId, state, code) => { log_1.default.info(`onChannelMediaRelayStateChanged targetChannelId:${targetChannelId},state: ${state}, code: ${code}`); this.rtcChannel.RtcChannelEvent.trigger('onChannelMediaRelayStateChanged', { targetChannelId, state, code }); }); this.rtcChannel.onEvent('serverForceCloseChannel', (channelId, code) => { log_1.default.info(`onServerForceCloseChannel channel:${channelId}, code: ${code}`); this.rtcChannel.RtcChannelEvent.trigger('onServerForceCloseChannel', { channelId, code }); }); this.rtcChannel.onEvent('historyDataReady', () => { log_1.default.info(`onHistoryDataReady`); this.rtcChannel.RtcChannelEvent.trigger('onHistoryDataReady'); }); this.rtcChannel.onEvent('audiovolumeindication', (deviceId) => { log_1.default.info(`onAudiovolumeindication`); this.rtcChannel.RtcChannelEvent.trigger('onVolumeIndication', { deviceId }); }); } } exports.default = MessageController;