UNPKG

zby-live-sdk

Version:

This is a live SDK for weclassroom.

436 lines (429 loc) 7.97 kB
/* * @Author: why * @Date: 2020-07-23 21:02:08 * @LastEditors: Please set LastEditors * @LastEditTime: 2021-06-02 19:05:07 * @Description: */ import SDK from './zby-live-sdk'; import defaultApi from './default/extend'; const noWriteLogNoticeNames = ['playerVolumeChanged', 'volume_change', 'real_time_mic_volume', 'pull_quality', 'push_quality', 'push_loss_delay', 'play_loss_delay']; setTimeout(() => { SDK.noWriteLogNoticeNames = noWriteLogNoticeNames; }); function notice(data) { if (!noWriteLogNoticeNames.includes(data.type)) { defaultApi.writeLog(`NOTICE--${JSON.stringify(data)}`); } try { SDK.notice(data); } catch (error) { console.error('zby-live-sdk callback error', data, error); } } export default { // sdk状态相关 // 初始化前 sdkStatus(data) { notice({ type: 'sdk_status', data }); }, // 切换sdk完成后返回本地预览地址 updateLocalPreview(data) { notice({ type: 'update_local_preview', data }); }, // 设备热插拔 hotPlug(data) { notice({ type: 'plug_and_unplug', data }); }, // 设备检测出现问题 deviceError(data) { notice({ type: 'device_error', data }); }, noDevice(data) { notice({ type: 'no_device', data }); }, useredCamera(data) { notice({ type: 'usered_camera', data }); }, // 播放器音量变化 playerVolumeChanged(data) { notice({ type: 'playerVolumeChanged', data }); }, // 同playerVolumeChanged volumeChange(data) { notice({ type: 'volume_change', data }); }, // 采集器麦克风音量变化 captureMicVolumeChanged(data) { notice({ type: 'real_time_mic_volume', data }); }, // sdk状态变化 sdkStatus(data) { notice({ type: 'sdk_status', data }); }, // 用户指定扬声器 speakerChanged(data) { notice({ type: 'speaker_changed', data }); }, // 默认麦克风改变 defaultMicChanged(data) { notice({ type: 'default_mic_changed', data }); }, // 默认扬声器改变 defaultSpeakerChanged(data) { notice({ type: 'default_speaker_changed', data }); }, // -------------信道消息--------- // 用户加入房间 userJoin(data) { notice({ type: 'user_join', data }); }, // 设备状态改变 deviceStatus(data) { notice({ type: 'device_status', data }); }, // 用户推流 remoteVideoReady(data) { notice({ type: 'remote_video_ready', data }); }, // 用户停止推流 remoteVideoRemoved(data) { notice({ type: 'remote_video_removed', data }); }, // 表示当前已经有用户在房间,对当前新进入房间用户的进行作出一次响应 userResponse(data) { notice({ type: 'userResponse', data }); }, // 信道断开 channelDisconnect() { notice({ type:'channel_disconnect', data: { message: 'Channel disconnect' } }); }, // 信道重连 channelReconnect() { notice({ type:'channel_reconnect', data: { message: 'Channel reconnect' } }); }, pushFlowSuccess(data) { notice({ type:'pushFlowSuccess', data }); }, pullFlowResult(data) { notice({ type:'pullFlowResult', data }); }, pullAudioFlowError(data) { notice({ type:'pullAudioFlowError', data }); }, // ----------播放器-------- // 播放出错 playError(data) { notice({ type:'play_error', data }); }, // 播放出错详细事件 playErrorDetail(data) { notice(data); }, // 视频首帧 firstVideoSize(data) { notice({ type:'firstVideoSize', data }); }, // 音频首帧 firstAudioSize(data) { notice({ type:'firstAudioSize', data }); }, // 通道id占用尽 overMaxConnect(data) { notice({ type: 'overMaxConnect', data, }); }, // 拉流质量 pullQuality(data) { notice({ type:'pull_quality', data }); }, // 推流质量 pushQuality(data) { notice({ type:'push_quality', data }); }, pushLossAndDelay(data) { notice({ type:'push_loss_delay', data }); }, playLossAndDelay(data) { notice({ type:'play_loss_delay', data }); }, // 更新本地预览视频,在切换SDK完成之后,会重新调起本地摄像头,需要更新本地预览的画面 updateLocalPreview(data) { notice({ type:'update_local_preview', data }); }, // 网络错误 networkError() { notice({ type:'network_error', data: { message: 'Network error' } }); }, // 网络重连 networkRecovery() { notice({ type:'network_recovery', data: { message: 'Network recovery' } }); }, // 录制成功回调 recordResponse(data) { notice({ type:'record_response', data }); }, streamStatus(data) { notice({ type:'stream_status', data }); }, // -------信道消息--------- join(data) { notice({ type: 'user_join', data }); }, joinAck(data) { notice({ type: 'user_response', data }); }, addStream(data) { notice({ type: 'remote_video_ready', data }); }, removeStream(data) { notice({ type: 'remote_video_removed', data }); }, updateStreamDeviceStatus(data) { notice({ type: 'device_status', data }); }, leave(data) { notice({ type: 'user_leave', data }); }, channelDisconnect() { notice({ type: 'channel_disconnect', data: { message: 'Channel disconnect' } }); }, userDisconnect(data) { notice({ type: 'user_disconnect', data }); }, zegoRecoveryStart(){ notice({ type:'zego_recovery_start', data: { message: 'zego is killed' } }) }, liveRecoveryStart(){ notice({ type:'live_recovery_start', data: { message: 'live is killed' } }) }, seiReceived(data){ notice({ type:'sei_received', data }) }, pushStreamError(data){ notice({ type:'push_stream_error', data }) }, pushStreamWarning(data){ notice({ type:'push_stream_warning', data }) }, pullStreamError(data){ notice({ type:'pull_stream_error', data }) }, pullStreamWarning(data){ notice({ type:'pull_stream_warning', data }) }, remoteNetworkQuality(data){ notice({ type:'remote_network_quality', data }) }, localNetworkQuality(data){ notice({ type:'local_network_quality', data }) }, recordStateUpdate(data){ notice({ type:'record_state_update', data }); }, recordFinished(data){ notice({ type:'record_finished', data }); }, recordError(data){ notice({ type:'record_error', data }); }, recordBegin(data){ notice({ type:'record_begin', data }); }, recordEnd(data){ notice({ type:'record_end', data }); }, beautifyError(data){ notice({ type:'beautify_error', data }); }, };