UNPKG

cloudhub-electron-sdk

Version:

cloudhub-electron-sdk

496 lines (495 loc) 20.4 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const BaseChannelController_1 = __importDefault(require("./BaseChannelController")); const log_1 = __importDefault(require("../helpers/log")); const utils_1 = __importDefault(require("../helpers/utils")); class CloudhubRtcChannel extends BaseChannelController_1.default { constructor(rtcChannel) { super(rtcChannel); log_1.default.info(`CloudhubRtcChannel contructor, ${rtcChannel}`, rtcChannel); this.rtcChannel = rtcChannel; } renewToken(token) { log_1.default.info(`renewToken token:${token}`); this.rtcChannel.renewToken(token); } setClientRole(role) { log_1.default.info(`setClientRole role:${role}`); this.rtcChannel.setClientRole(role); } setChannelProfile(profile) { log_1.default.info(`setChannelProfile profile:${profile}`); this.rtcChannel.setChannelProfile(profile); } setAddonLogFile(fullpath) { log_1.default.info(`setAddonLogFile fullpath:${fullpath}`); this.rtcChannel.setAddonLogFile(fullpath); } joinChannel(token, info, uid, channelMediaOptions) { log_1.default.info(`子房间joinChannel token:${token} info:${utils_1.default.jsonToStr(info)} uid:${uid}`); this.rtcChannel.joinChannel(token, utils_1.default.jsonToStr(info), uid, channelMediaOptions); } leaveChannel() { log_1.default.info('leaveChannel'); this.rtcChannel.leaveChannel(); } release() { log_1.default.info('release方法'); this.rtcChannel.release(); } publish(options) { const { deviceId = '', streamInfo = {} } = options || {}; log_1.default.info(`publish, deviceId: ${deviceId}, streamInfo:`, streamInfo); if (streamInfo && utils_1.default.isObject(streamInfo)) { this.rtcChannel.setPublishStreamInfo(JSON.stringify(streamInfo), deviceId); } this.rtcChannel.publish(deviceId); } unPublish(options) { const { deviceId = '' } = options || {}; log_1.default.info(`unPublish, deviceId: ${deviceId}`); this.rtcChannel.unpublish(deviceId); } enableLocalVideo(enable, options) { const { deviceId = '' } = options || {}; log_1.default.info(`enableLocalVideo, enable:${enable}, deviceId: ${deviceId}`); this.rtcChannel.enableLocalVideo(enable, deviceId); } enableLocalAudio(enable) { log_1.default.info(`enableLocalAudio enable:${enable}`); this.rtcChannel.enableLocalAudio(enable); } enableVideo() { log_1.default.info('enableVideo'); this.rtcChannel.enableVideo(); } disableVideo() { log_1.default.info('disableVideo'); this.rtcChannel.disableVideo(); } muteLocalVideoStream(mute, options) { const { deviceId = '' } = options || {}; log_1.default.info(`muteLocalVideoStream,mute:${mute}, deviceId:${deviceId}`); this.rtcChannel.muteLocalVideoStream(mute, deviceId); } muteLocalAudioStream(mute) { log_1.default.info(`muteLocalAudioStream mute:${mute}`); this.rtcChannel.muteLocalAudioStream(mute); } muteRemoteVideoStream(streamId, mute) { log_1.default.info(`muteRemoteVideoStream streamId:${streamId} mute:${mute}`); this.rtcChannel.muteRemoteVideoByStream(streamId, mute); } muteRemoteAudioStream(uid, mute) { log_1.default.info(`muteRemoteAudioStream uid:${uid} mute:${mute}`); this.rtcChannel.muteRemoteAudioStream(uid, mute); } muteAllRemoteVideoStreams(mute) { log_1.default.info(`muteAllRemoteVideoStreams mute:${mute}`); this.rtcChannel.muteAllRemoteVideoStreams(mute); } muteAllRemoteAudioStreams(mute) { log_1.default.info(`muteAllRemoteAudioStreams mute:${mute}`); this.rtcChannel.muteAllRemoteAudioStreams(mute); } getVideoDevices() { log_1.default.info('getVideoDevices'); return this.rtcChannel.getVideoDevices(); } getAudioRecordingDevices() { log_1.default.info('getAudioRecordingDevices'); return this.rtcChannel.getAudioRecordingDevices(); } getAudioPlaybackDevices() { log_1.default.info('getAudioPlaybackDevices'); return this.rtcChannel.getAudioPlaybackDevices(); } getCurrentVideoDevice() { log_1.default.info('getCurrentVideoDevice'); return this.rtcChannel.getCurrentVideoDevice(); } getCurrentAudioRecordingDevice() { log_1.default.info('getCurrentAudioRecordingDevice'); return this.rtcChannel.getCurrentAudioRecordingDevice(); } getCurrentAudioPlaybackDevice() { log_1.default.info('getCurrentAudioPlaybackDevice'); return this.rtcChannel.getCurrentAudioPlaybackDevice(); } setVideoDevice(deviceId) { log_1.default.info('setVideoDevice', deviceId); if (!deviceId) return; this.rtcChannel.setVideoDevice(deviceId); } setAudioRecordingDevice(deviceId) { log_1.default.info('setAudioRecordingDevice', deviceId); if (!deviceId) return; this.rtcChannel.setAudioRecordingDevice(deviceId); } setAudioPlaybackDevice(deviceId) { log_1.default.info('setAudioPlaybackDevice', deviceId); if (!deviceId) return; this.rtcChannel.setAudioPlaybackDevice(deviceId); } removeLocalVideo(view, options) { if (!view.id) return; let { deviceId = '' } = options || {}; if (!deviceId) { const currentVideoDevice = this.rtcChannel.getCurrentVideoDevice() || {}; deviceId = currentVideoDevice.deviceid; } this._removeLocalVideo(deviceId, view.id); } removeLocalMovie(movieUrl) { log_1.default.info(`removeLocalMovie movieUrl:${movieUrl}`); this._removeLocalVideo(movieUrl, movieUrl); } removeRemoteVideo(uid, streamId) { log_1.default.info(`removeRemoteVideo uid:${uid} type:${streamId}`); this._removeRemoteVideo(uid, streamId); } getMovieDuration(mediaFile) { log_1.default.info(`getMovieDuration mediaFile:${mediaFile}`); return this.rtcChannel.getMovieDuration(mediaFile); } setLocalVideoMirror(mirror, options) { const { viewId = '' } = options || {}; log_1.default.info(`setLocalVideoMirror, mirror:${mirror}, viewId: ${viewId}`); if (viewId) { const stream = this.streamInstance.getStreamByViewId(viewId); if (stream) { stream.renderer.setMirror(mirror); } } else { const streams = this.streamInstance.getLocalStreams(); streams.forEach((stream) => { stream.renderer.setMirror(mirror); }); } } setVideoMode(viewId, mode) { log_1.default.info(`setVideoMode, viewId:${viewId} mode:${mode}`); this._setVideoMode(viewId, mode); } playAVFileFromLibrary(url, attr) { log_1.default.info('playAVFileFromLibrary', url, utils_1.default.jsonToStr(attr)); if (!url) return; this.rtcChannel.playAVFileFromLibrary(url, utils_1.default.jsonToStr(attr)); } unplayAVFileFromLibrary(url) { log_1.default.info('unplayAVFileFromLibrary', url); if (!url) return; this.rtcChannel.unplayAVFileFromLibrary(url); } pauseAVFileFromLibrary(url, isPause) { log_1.default.info('pauseAVFileFromLibrary', url, isPause); if (!url) return; this.rtcChannel.pauseAVFileFromLibrary(url, isPause); } seekAVFileFromLibrary(url, position) { log_1.default.info('seekAVFileFromLibrary', url, position); if (!url) return; this.rtcChannel.seekAVFileFromLibrary(url, position); } startPlayMovie(mediaFile, loopback, cycle, paused = false) { log_1.default.info('startPlayMovie', mediaFile, loopback, cycle, paused); if (!mediaFile) return; this.rtcChannel.startPlayMovie(mediaFile, loopback, cycle, paused); } stopPlayMovie(mediaFile) { log_1.default.info('stopPlayMovie', mediaFile); if (!mediaFile) return; this.rtcChannel.stopPlayMovie(mediaFile); } setMoviePosition(mediaFile, pos) { log_1.default.info('setMoviePosition', mediaFile, pos); if (!mediaFile) return; this.rtcChannel.setMoviePosition(mediaFile, utils_1.default.strToNum(pos)); } pausePlayMovie(mediaFile) { log_1.default.info('pausePlayMovie', mediaFile); if (!mediaFile) return; this.rtcChannel.pausePlayMovie(mediaFile); } resumePlayMovie(mediaFile) { log_1.default.info('resumePlayMovie', mediaFile); if (!mediaFile) return; this.rtcChannel.resumePlayMovie(mediaFile); } getMovieCurrentPosition(mediaFile) { log_1.default.info('getMovieCurrentPosition', mediaFile); if (!mediaFile) return false; return this.rtcChannel.getMovieCurrentPosition(mediaFile); } getMovieInfo(mediaFile) { log_1.default.info('getMovieInfo', mediaFile); if (!mediaFile) return false; return this.rtcChannel.getMovieInfo(mediaFile); } evictUser(uid, reason) { log_1.default.info('evictUser', uid, reason); this.rtcChannel.evictUser(uid, reason); } stopVideoDeviceTest(deviceId) { log_1.default.info(`stopVideoDeviceTest, deviceId:${deviceId}`); const videoTest = document.getElementById("cloudhub-video-device-test"); if (videoTest && deviceId) { this._removeLocalVideo(deviceId, videoTest.id); const viewParent = videoTest.parentNode; viewParent.removeChild(videoTest); } } enableAudioVolumeIndication(interval, smooth = 3, reportVad = false) { log_1.default.info(`enableAudioVolumeIndication interval:${interval}, smooth:${smooth}, reportVad:${reportVad}`); this.rtcChannel.enableAudioVolumeIndication(interval, smooth, reportVad); } startAudioPlaybackDeviceTest(deviceId, filepath, options = { loop: true }) { log_1.default.info(`startAudioPlaybackDeviceTest deviceId:${deviceId} filepath:${filepath} options:${options}`); if (deviceId) { this.setAudioPlaybackDevice(deviceId); } if (!filepath) { return; } this.rtcChannel.startAudioPlaybackDeviceTest(deviceId, filepath, options.loop); } stopAudioPlaybackDeviceTest() { log_1.default.info(`stopAudioPlaybackDeviceTest`); this.rtcChannel.stopAudioPlaybackDeviceTest(); } startAudioRecordingDeviceTest(deviceId, interval = 200) { log_1.default.info(`startAudioRecordingDeviceTest deviceId:${deviceId} interval:${interval}`); if (deviceId) { this.setAudioRecordingDevice(deviceId); } this.rtcChannel.startAudioRecordingDeviceTest(interval); } stopAudioRecordingDeviceTest() { log_1.default.info(`stopAudioRecordingDeviceTest`); this.rtcChannel.stopAudioRecordingDeviceTest(); } getVersion() { log_1.default.info('getVersion'); return this.rtcChannel.getVersion(); } on(event, callback, markId) { this.RtcChannelEvent.on(event, callback, markId); } off(event, callback) { this.RtcChannelEvent.off(event, callback); } offAll(event) { this.RtcChannelEvent.offAll(event); } offAllByMarkId(markId) { this.RtcChannelEvent.offAllByMarkId(markId); } trigger(event, data) { this.RtcChannelEvent.trigger(event, data); } sendChatMsg(toId, message, extraData) { log_1.default.info('sendChatMsg', toId, message, utils_1.default.jsonToStr(extraData)); if (!message) return; this.rtcChannel.sendChatMsg(toId, message, utils_1.default.jsonToStr(extraData)); } setProperty(uid, toId, prop) { log_1.default.info('setProperty', uid, toId, utils_1.default.jsonToStr(prop)); if (!uid) return; this.rtcChannel.setProperty(uid, toId, utils_1.default.jsonToStr(prop)); } pubMsg(msgName, msgId, toId, data, associatedUserId, associatedMsgId, bSave, extraInfo) { log_1.default.info('pubMsg', msgName, msgId, toId, data, associatedUserId, associatedMsgId, bSave, extraInfo); this.rtcChannel.pubMsg(msgName, msgId, toId, utils_1.default.jsonToStr(data), associatedUserId, associatedMsgId, bSave, utils_1.default.jsonToStr(extraInfo)); } delMsg(msgName, msgId, toId, data) { log_1.default.info('delMsg', msgName, msgId, toId, utils_1.default.jsonToStr(data)); this.rtcChannel.delMsg(msgName, msgId, toId, utils_1.default.jsonToStr(data)); } setVideoEncoderConfiguration(config) { log_1.default.info('setVideoEncoderConfiguration', config); if (!config) return; const { deviceId = '' } = config; this.rtcChannel.setVideoEncoderConfiguration(config, deviceId); } getScreenWindowsInfo() { log_1.default.info(`getScreenWindowsInfo`); return this.rtcChannel.getScreenWindowsInfo(); } getScreenDisplaysInfo() { log_1.default.info(`getScreenDisplaysInfo`); return this.rtcChannel.getScreenDisplaysInfo(); } startScreenCaptureByDisplayId(displayId, excludeWindow, framerate, bitrate, isCaptureCursor) { log_1.default.info('startScreenCaptureByDisplayId', displayId, excludeWindow, framerate, bitrate, isCaptureCursor); this.rtcChannel.startScreenCaptureByDisplayId(displayId, excludeWindow, framerate, bitrate, isCaptureCursor); } startScreenCaptureByWindowId(windowId, excludeWindow = 0, framerate = 5, bitrate = 1200, isCaptureCursor = false) { log_1.default.info('startScreenCaptureByWindowId', windowId, excludeWindow, framerate, bitrate, isCaptureCursor); return this.rtcChannel.startScreenCaptureByWindowId(windowId, excludeWindow, framerate, bitrate, isCaptureCursor); } startSpeakerCaptureWhileSharing() { log_1.default.info(`startSpeakerCaptureWhileSharing`); return this.rtcChannel.startSpeakerCaptureWhileSharing(); } stopSpeakerCaptureWhileSharing() { log_1.default.info(`stopSpeakerCaptureWhileSharing`); return this.rtcChannel.stopSpeakerCaptureWhileSharing(); } setCameraFlip(horiz, deviceId = '') { return this.rtcChannel.setCameraFlip(horiz, false, deviceId); } startRecordingVoiceClip(baseName, duration) { return this.rtcChannel.startRecordingVoiceClip(baseName, duration); } stopRecordingVoiceClip(baseName) { return this.rtcChannel.stopRecordingVoiceClip(baseName); } stopScreenCapture() { log_1.default.info(`stopScreenCapture`); this.rtcChannel.stopScreenCapture(); } startServerRecord() { log_1.default.info(`startServerRecord`); this.rtcChannel.startServerRecord(); } stopServerRecord() { log_1.default.info(`stopServerRecord`); this.rtcChannel.stopServerRecord(); } pauseServerRecord() { log_1.default.info(`pauseServerRecord`); this.rtcChannel.pauseServerRecord(); } resumeServerRecord() { log_1.default.info(`resumeServerRecord`); this.rtcChannel.resumeServerRecord(); } getEffectsVolume() { log_1.default.info(`getEffectsVolume`); return this.rtcChannel.getEffectsVolume(); } setEffectsVolume(volume) { log_1.default.info(`setEffectsVolume`); return this.rtcChannel.setEffectsVolume(volume); } setVolumeOfEffect(soundId, volume) { log_1.default.info(`setVolumeOfEffect`); return this.rtcChannel.setVolumeOfEffect(soundId, volume); } playEffect(soundId, filePath, loopcount, gain, publish, startTimeMS, endTimeMS) { log_1.default.info(`playEffect`); return this.rtcChannel.playEffect(soundId, filePath, loopcount, gain, publish, startTimeMS, endTimeMS); } stopEffect(soundId) { log_1.default.info(`stopEffect`); return this.rtcChannel.stopEffect(soundId); } stopAllEffects() { log_1.default.info(`stopAllEffects`); return this.rtcChannel.stopAllEffects(); } pauseEffect(soundId) { log_1.default.info(`pauseEffect`); return this.rtcChannel.pauseEffect(soundId); } pauseAllEffects() { log_1.default.info(`pauseAllEffects`); return this.rtcChannel.pauseAllEffects(); } resumeEffect(soundId) { log_1.default.info(`resumeEffect`); return this.rtcChannel.resumeEffect(soundId); } resumeAllEffects() { log_1.default.info(`resumeAllEffects`); return this.rtcChannel.resumeAllEffects(); } preloadEffect(soundId, filePath) { log_1.default.info(`preloadEffect`); return this.rtcChannel.preloadEffect(soundId, filePath); } unloadEffect(soundId) { log_1.default.info(`unloadloadEffect`); return this.rtcChannel.unloadEffect(soundId); } addPublishStreamUrl(url, transcodingEnabled) { log_1.default.info(`addPublishStreamUrl`); return this.rtcChannel.addPublishStreamUrl(url, transcodingEnabled); } removePublishStreamUrl(url) { log_1.default.info(`removePublishStreamUrl`); return this.rtcChannel.removePublishStreamUrl(url); } setLiveTranscoding(transcoding) { log_1.default.info(`setLiveTranscoding, ${transcoding}`); transcoding.transcodingStreams = transcoding.transcodingStreams.map((it) => { if (it.type === 'video') { it.sourceID = 'default_source_id'; } else if (it.type === 'screen ') { it.sourceID = 'screen'; } else if (it.type === 'file') { it.sourceID = 'file'; } return it; }); return this.rtcChannel.setLiveTranscoding(JSON.stringify(transcoding)); } startLastmileProbeTest(config) { log_1.default.info(`startLastmileProbeTest`); return this.rtcChannel.startLastmileProbeTest(config); } stopLastmileProbeTest() { log_1.default.info(`stopLastmileProbeTest`); return this.rtcChannel.stopLastmileProbeTest(); } startChannelMediaRelay(config) { log_1.default.info(`startChannelMediaRelay`, config); return this.rtcChannel.startChannelMediaRelay(JSON.stringify(config)); } updateChannelMediaRelay(config) { log_1.default.info(`updateChannelMediaRelay`); return this.rtcChannel.updateChannelMediaRelay(JSON.stringify(config)); } stopChannelMediaRelay() { log_1.default.info(`stopChannelMediaRelay`); return this.rtcChannel.stopChannelMediaRelay(); } sendBuriedPointEvent(data) { return this.rtcChannel.eventReport(JSON.stringify(data)); } setBeautyEffectOptions(enable, options, deviceId = '') { return this.rtcChannel.setBeautyEffectOptions(enable, options, deviceId); } setVideoEffectOptions(enable, options, deviceId = '') { return this.rtcChannel.setVideoEffectOptions(enable, options, deviceId); } adjustUserPlaybackSignalVolume(uid, volume) { log_1.default.info(`adjustUserPlaybackSignalVolume, uid:${uid} volume:${volume}`); return this.rtcChannel.adjustUserPlaybackSignalVolume(uid, Number(volume)); } } exports.default = CloudhubRtcChannel;