UNPKG

trtc-electron-sdk

Version:

trtc electron sdk

423 lines (422 loc) 22.1 kB
"use strict"; /** * V2Live 关键类型定义 */ Object.defineProperty(exports, "__esModule", { value: true }); exports.V2LivePushStatus = exports.V2LivePusherStatistics = exports.V2LiveAudioQuality = exports.V2LiveBufferType = exports.V2LivePixelFormat = exports.V2LiveRotation = exports.V2LiveFillMode = exports.V2LiveMirrorType = exports.V2LiveVideoEncoderParam = exports.V2LiveVideoResolutionMode = exports.V2LiveVideoResolution = exports.V2LivePusherEvent = exports.V2LiveMode = exports.V2LiveCode = void 0; ///////////////////////////////////////////////////////////////////////////////// // // V2 错误码和警告码 // ///////////////////////////////////////////////////////////////////////////////// /** * V2 错误码和警告码 * * @enum {Number} */ const V2LiveCode_HACK_JSDOC = { /** 没有错误。*/ V2LIVE_OK: 0, /** 暂未归类的通用错误。*/ V2LIVE_ERROR_FAILED: -1, /** 调用 API 时,传入的参数不合法。*/ V2LIVE_ERROR_INVALID_PARAMETER: -2, /** API 调用被拒绝。*/ V2LIVE_ERROR_REFUSED: -3, /** 当前 API 不支持调用。*/ V2LIVE_ERROR_NOT_SUPPORTED: -4, /** license 不合法,调用失败。*/ V2LIVE_ERROR_INVALID_LICENSE: -5, /** 请求服务器超时。*/ V2LIVE_ERROR_REQUEST_TIMEOUT: -6, /** 服务器无法处理您的请求。*/ V2LIVE_ERROR_SERVER_PROCESS_FAILED: -7, /** 连接断开。*/ V2LIVE_ERROR_DISCONNECTED: -8, /** 找不到可用的 HEVC 解码器。*/ V2LIVE_ERROR_NO_AVAILABLE_HEVC_DECODERS: -2304, /** 网络状况不佳:上行带宽太小,上传数据受阻。*/ V2LIVE_WARNING_NETWORK_BUSY: 1101, /** 当前视频播放出现卡顿。*/ V2LIVE_WARNING_VIDEO_BLOCK: 2105, }; var V2LiveCode; (function (V2LiveCode) { V2LiveCode[V2LiveCode["V2LIVE_OK"] = 0] = "V2LIVE_OK"; V2LiveCode[V2LiveCode["V2LIVE_ERROR_FAILED"] = -1] = "V2LIVE_ERROR_FAILED"; V2LiveCode[V2LiveCode["V2LIVE_ERROR_INVALID_PARAMETER"] = -2] = "V2LIVE_ERROR_INVALID_PARAMETER"; V2LiveCode[V2LiveCode["V2LIVE_ERROR_REFUSED"] = -3] = "V2LIVE_ERROR_REFUSED"; V2LiveCode[V2LiveCode["V2LIVE_ERROR_NOT_SUPPORTED"] = -4] = "V2LIVE_ERROR_NOT_SUPPORTED"; V2LiveCode[V2LiveCode["V2LIVE_ERROR_INVALID_LICENSE"] = -5] = "V2LIVE_ERROR_INVALID_LICENSE"; V2LiveCode[V2LiveCode["V2LIVE_ERROR_REQUEST_TIMEOUT"] = -6] = "V2LIVE_ERROR_REQUEST_TIMEOUT"; V2LiveCode[V2LiveCode["V2LIVE_ERROR_SERVER_PROCESS_FAILED"] = -7] = "V2LIVE_ERROR_SERVER_PROCESS_FAILED"; V2LiveCode[V2LiveCode["V2LIVE_ERROR_DISCONNECTED"] = -8] = "V2LIVE_ERROR_DISCONNECTED"; V2LiveCode[V2LiveCode["V2LIVE_ERROR_NO_AVAILABLE_HEVC_DECODERS"] = -2304] = "V2LIVE_ERROR_NO_AVAILABLE_HEVC_DECODERS"; V2LiveCode[V2LiveCode["V2LIVE_WARNING_NETWORK_BUSY"] = 1101] = "V2LIVE_WARNING_NETWORK_BUSY"; V2LiveCode[V2LiveCode["V2LIVE_WARNING_VIDEO_BLOCK"] = 2105] = "V2LIVE_WARNING_VIDEO_BLOCK"; })(V2LiveCode = exports.V2LiveCode || (exports.V2LiveCode = {})); ///////////////////////////////////////////////////////////////////////////////// // // 支持协议 // ///////////////////////////////////////////////////////////////////////////////// /** * 支持协议 * * @enum {Number} */ const V2LiveMode_HACK_JSDOC = { /** 支持协议: RTMP。*/ V2LiveModeRTMP: 0, /** 支持协议: TRTC。*/ V2LiveModeRTC: 1, }; var V2LiveMode; (function (V2LiveMode) { V2LiveMode[V2LiveMode["V2LiveModeRTMP"] = 0] = "V2LiveModeRTMP"; V2LiveMode[V2LiveMode["V2LiveModeRTC"] = 1] = "V2LiveModeRTC"; })(V2LiveMode = exports.V2LiveMode || (exports.V2LiveMode = {})); ///////////////////////////////////////////////////////////////////////////////// // // V2LivePusher 事件定义 // ///////////////////////////////////////////////////////////////////////////////// /** * @namespace V2LivePusherEvent * @description V2LivePusher 事件定义 * */ var V2LivePusherEvent; (function (V2LivePusherEvent) { /** * @description 错误回调:SDK 不可恢复的错误,一定要监听,并分情况给用户适当的界面提示。 * * @event V2LivePusherEvent#onError * @param {Number} errCode - 错误码 * @param {String} errMsg - 错误信息 */ V2LivePusherEvent["onError"] = "onError"; /** * @description 警告回调:SDK 可恢复的错误,需要监听,并给用户适当的界面提示。 * * @event V2LivePusherEvent#onWarning * @param {Number} warnCode - 警告码 * @param {String} warnMsg - 警告信息 */ V2LivePusherEvent["onWarning"] = "onWarning"; /** * @description 音频采集状态回调:音频采集状态回调。 * * @event V2LivePusherEvent#onCaptureFirstAudioFrame */ V2LivePusherEvent["onCaptureFirstAudioFrame"] = "onCaptureFirstAudioFrame"; /** * @description 视频采集状态回调:视频采集状态回调。 * * @event V2LivePusherEvent#onCaptureFirstVideoFrame */ V2LivePusherEvent["onCaptureFirstVideoFrame"] = "onCaptureFirstVideoFrame"; /** * @description 麦克风音量回调:麦克风音量回调。 * * @event V2LivePusherEvent#onMicrophoneVolumeUpdate * @param {Number} volume - 麦克风音量 */ V2LivePusherEvent["onMicrophoneVolumeUpdate"] = "onMicrophoneVolumeUpdate"; /** * @description 推流状态更新回调:推流状态更新回调。 * * @event V2LivePusherEvent#onPushStatusUpdate * @param {Number} status - 推流状态 * @param {String} message - 推流状态信息 */ V2LivePusherEvent["onPushStatusUpdate"] = "onPushStatusUpdate"; /** * @description 推流统计回调:推流统计信息变化时,会回调该接口。 * * @event V2LivePusherEvent#onStatisticsUpdate * @param {V2LivePusherStatistics} statistics - 推流统计信息 */ V2LivePusherEvent["onStatisticsUpdate"] = "onStatisticsUpdate"; })(V2LivePusherEvent = exports.V2LivePusherEvent || (exports.V2LivePusherEvent = {})); ///////////////////////////////////////////////////////////////////////////////// // // (一)视频相关类型定义 // ///////////////////////////////////////////////////////////////////////////////// /** * 视频分辨率 * * @enum {Number} */ const V2LiveVideoResolution_HACK_JSDOC = { /** 分辨率 160*160,码率范围:100Kbps ~ 150Kbps,帧率:15fps。*/ V2LiveVideoResolution160x160: 0, /** 分辨率 270*270,码率范围:200Kbps ~ 300Kbps,帧率:15fps。*/ V2LiveVideoResolution270x270: 1, /** 分辨率 480*480,码率范围:350Kbps ~ 525Kbps,帧率:15fps。*/ V2LiveVideoResolution480x480: 2, /** 分辨率 320*240,码率范围:250Kbps ~ 375Kbps,帧率:15fps。*/ V2LiveVideoResolution320x240: 3, /** 分辨率 480*360,码率范围:400Kbps ~ 600Kbps,帧率:15fps。*/ V2LiveVideoResolution480x360: 4, /** 分辨率 640*480,码率范围:600Kbps ~ 900Kbps,帧率:15fps。*/ V2LiveVideoResolution640x480: 5, /** 分辨率 320*180,码率范围:250Kbps ~ 400Kbps,帧率:15fps。*/ V2LiveVideoResolution320x180: 6, /** 分辨率 480*270,码率范围:350Kbps ~ 550Kbps,帧率:15fps。*/ V2LiveVideoResolution480x270: 7, /** 分辨率 640*360,码率范围:500Kbps ~ 900Kbps,帧率:15fps。*/ V2LiveVideoResolution640x360: 8, /** 分辨率 960*540,码率范围:800Kbps ~ 1500Kbps,帧率:15fps。*/ V2LiveVideoResolution960x540: 9, /** 分辨率 1280*720,码率范围:1000Kbps ~ 1800Kbps,帧率:15fps。*/ V2LiveVideoResolution1280x720: 10, /** 分辨率 1920*1080,码率范围:2500Kbps ~ 3000Kbps,帧率:15fps。*/ V2LiveVideoResolution1920x1080: 11, }; var V2LiveVideoResolution; (function (V2LiveVideoResolution) { V2LiveVideoResolution[V2LiveVideoResolution["V2LiveVideoResolution160x160"] = 0] = "V2LiveVideoResolution160x160"; V2LiveVideoResolution[V2LiveVideoResolution["V2LiveVideoResolution270x270"] = 1] = "V2LiveVideoResolution270x270"; V2LiveVideoResolution[V2LiveVideoResolution["V2LiveVideoResolution480x480"] = 2] = "V2LiveVideoResolution480x480"; V2LiveVideoResolution[V2LiveVideoResolution["V2LiveVideoResolution320x240"] = 3] = "V2LiveVideoResolution320x240"; V2LiveVideoResolution[V2LiveVideoResolution["V2LiveVideoResolution480x360"] = 4] = "V2LiveVideoResolution480x360"; V2LiveVideoResolution[V2LiveVideoResolution["V2LiveVideoResolution640x480"] = 5] = "V2LiveVideoResolution640x480"; V2LiveVideoResolution[V2LiveVideoResolution["V2LiveVideoResolution320x180"] = 6] = "V2LiveVideoResolution320x180"; V2LiveVideoResolution[V2LiveVideoResolution["V2LiveVideoResolution480x270"] = 7] = "V2LiveVideoResolution480x270"; V2LiveVideoResolution[V2LiveVideoResolution["V2LiveVideoResolution640x360"] = 8] = "V2LiveVideoResolution640x360"; V2LiveVideoResolution[V2LiveVideoResolution["V2LiveVideoResolution960x540"] = 9] = "V2LiveVideoResolution960x540"; V2LiveVideoResolution[V2LiveVideoResolution["V2LiveVideoResolution1280x720"] = 10] = "V2LiveVideoResolution1280x720"; V2LiveVideoResolution[V2LiveVideoResolution["V2LiveVideoResolution1920x1080"] = 11] = "V2LiveVideoResolution1920x1080"; })(V2LiveVideoResolution = exports.V2LiveVideoResolution || (exports.V2LiveVideoResolution = {})); /** * 视频宽高比模式 * * 横屏模式下的分辨率: V2LiveVideoResolution640x360 + V2LiveVideoResolutionModeLandscape = 640 × 360。 * 竖屏模式下的分辨率: V2LiveVideoResolution640x360 + V2LiveVideoResolutionModePortrait = 360 × 640。 * * @enum {Number} */ const V2LiveVideoResolutionMode_HACK_JSDOC = { /** 横屏模式。*/ V2LiveVideoResolutionModeLandscape: 0, /** 竖屏模式。*/ V2LiveVideoResolutionModePortrait: 1, }; var V2LiveVideoResolutionMode; (function (V2LiveVideoResolutionMode) { V2LiveVideoResolutionMode[V2LiveVideoResolutionMode["V2LiveVideoResolutionModeLandscape"] = 0] = "V2LiveVideoResolutionModeLandscape"; V2LiveVideoResolutionMode[V2LiveVideoResolutionMode["V2LiveVideoResolutionModePortrait"] = 1] = "V2LiveVideoResolutionModePortrait"; })(V2LiveVideoResolutionMode = exports.V2LiveVideoResolutionMode || (exports.V2LiveVideoResolutionMode = {})); /** * 视频编码参数 * * 该设置决定远端用户看到的画面质量。、 * * @param {V2LiveVideoResolution} videoResolution - 【字段含义】 视频分辨率。 * - 【特别说明】如需使用竖屏分辨率,请指定 videoResolutionMode 为 Portrait,例如: 640 × 360 + Portrait = 360 × 640。 * - 【推荐取值】 * - 注意:桌面平台(Win + Mac):建议选择 640 × 360 及以上分辨率,videoResolutionMode 选择 Landscape,即横屏分辨率。 * @param {V2LiveVideoResolutionMode} videoResolutionMode - 【字段含义】分辨率模式(横屏分辨率 or 竖屏分辨率)。 * - 【推荐取值】桌面平台(Windows、Mac)建议选择 Landscape。 * - 【特别说明】如需使用竖屏分辨率,请指定 resMode 为 Portrait,例如: 640 × 360 + Portrait = 360 × 640。 * @param {Number} videoFps - 【字段含义】视频采集帧率。 * - 【推荐取值】15fps 或 20fps。5fps 以下,卡顿感明显。10fps 以下,会有轻微卡顿感。20fps 以上,会浪费带宽(电影的帧率为 24fps)。 * @param {Number} videoBitrate - 【字段含义】目标视频码率,SDK 会按照目标码率进行编码,只有在弱网络环境下才会主动降低视频码率。 * - 【推荐取值】请参考 V2LiveVideoResolution 在各档位注释的最佳码率,也可以在此基础上适当调高。 * - 比如:V2LiveVideoResolution1280x720 对应 1200kbps 的目标码率,您也可以设置为 1500kbps 用来获得更好的观感清晰度。 * - 【特别说明】您可以通过同时设置 videoBitrate 和 minVideoBitrate 两个参数,用于约束 SDK 对视频码率的调整范围: * - 如果您将 videoBitrate 和 minVideoBitrate 设置为同一个值,等价于关闭 SDK 对视频码率的自适应调节能力。 * @param {Number} minVideoBitrate - 【字段含义】最低视频码率,SDK 会在网络不佳的情况下主动降低视频码率以保持流畅度,最低会降至 minVideoBitrate 所设定的数值。 * - 【推荐取值】您可以通过同时设置 videoBitrate 和 minVideoBitrate 两个参数,用于约束 SDK 对视频码率的调整范围: * - 如果您将 videoBitrate 和 minVideoBitrate 设置为同一个值,等价于关闭 SDK 对视频码率的自适应调节能力。 */ class V2LiveVideoEncoderParam { constructor(videoResolution = V2LiveVideoResolution.V2LiveVideoResolution640x360, videoResolutionMode = V2LiveVideoResolutionMode.V2LiveVideoResolutionModeLandscape, videoFps = 15, videoBitrate = 0, minVideoBitrate = 0) { this.videoResolution = videoResolution; this.videoResolutionMode = videoResolutionMode; this.videoFps = videoFps; this.videoBitrate = videoBitrate; this.minVideoBitrate = minVideoBitrate; } } exports.V2LiveVideoEncoderParam = V2LiveVideoEncoderParam; /** * 本地摄像头镜像类型 * * @enum {Number} */ const V2LiveMirrorType_HACK_JSDOC = { /** 系统默认镜像类型,前置摄像头镜像,后置摄像头不镜像。*/ V2LiveMirrorTypeAuto: 0, /** 前置摄像头和后置摄像头,都切换为镜像模式。*/ V2LiveMirrorTypeEnable: 1, /** 前置摄像头和后置摄像头,都切换为非镜像模式。*/ V2LiveMirrorTypeDisable: 2, }; var V2LiveMirrorType; (function (V2LiveMirrorType) { V2LiveMirrorType[V2LiveMirrorType["V2LiveMirrorTypeAuto"] = 0] = "V2LiveMirrorTypeAuto"; V2LiveMirrorType[V2LiveMirrorType["V2LiveMirrorTypeEnable"] = 1] = "V2LiveMirrorTypeEnable"; V2LiveMirrorType[V2LiveMirrorType["V2LiveMirrorTypeDisable"] = 2] = "V2LiveMirrorTypeDisable"; })(V2LiveMirrorType = exports.V2LiveMirrorType || (exports.V2LiveMirrorType = {})); /** * 视频画面填充模式 * * @enum {Number} */ const V2LiveFillMode_HACK_JSDOC = { /** 图像铺满屏幕,超出显示视窗的视频部分将被裁剪,画面显示可能不完整。*/ V2LiveFillModeFill: 0, /** 图像长边填满屏幕,短边区域会被填充黑色,画面的内容完整。*/ V2LiveFillModeFit: 1, }; var V2LiveFillMode; (function (V2LiveFillMode) { V2LiveFillMode[V2LiveFillMode["V2LiveFillModeFill"] = 0] = "V2LiveFillModeFill"; V2LiveFillMode[V2LiveFillMode["V2LiveFillModeFit"] = 1] = "V2LiveFillModeFit"; })(V2LiveFillMode = exports.V2LiveFillMode || (exports.V2LiveFillMode = {})); /** * 视频画面顺时针旋转角度 * * @enum {Number} */ const V2LiveRotation_HACK_JSDOC = { /** 不旋转。*/ V2LiveRotation0: 0, /** 顺时针旋转90度。*/ V2LiveRotation90: 1, /** 顺时针旋转180度。*/ V2LiveRotation180: 2, /** 顺时针旋转270度。*/ V2LiveRotation270: 3, }; var V2LiveRotation; (function (V2LiveRotation) { V2LiveRotation[V2LiveRotation["V2LiveRotation0"] = 0] = "V2LiveRotation0"; V2LiveRotation[V2LiveRotation["V2LiveRotation90"] = 1] = "V2LiveRotation90"; V2LiveRotation[V2LiveRotation["V2LiveRotation180"] = 2] = "V2LiveRotation180"; V2LiveRotation[V2LiveRotation["V2LiveRotation270"] = 3] = "V2LiveRotation270"; })(V2LiveRotation = exports.V2LiveRotation || (exports.V2LiveRotation = {})); /** * 视频帧的像素格式 * * @enum {Number} */ const V2LivePixelFormat_HACK_JSDOC = { /** 未知。*/ V2LivePixelFormatUnknown: 0, /** I420。*/ V2LivePixelFormatI420: 1, /** BGRA8888。*/ V2LivePixelFormatBGRA32: 2, /** RGBA32。*/ V2LivePixelFormatRGBA32: 3, }; var V2LivePixelFormat; (function (V2LivePixelFormat) { V2LivePixelFormat[V2LivePixelFormat["V2LivePixelFormatUnknown"] = 0] = "V2LivePixelFormatUnknown"; V2LivePixelFormat[V2LivePixelFormat["V2LivePixelFormatI420"] = 1] = "V2LivePixelFormatI420"; V2LivePixelFormat[V2LivePixelFormat["V2LivePixelFormatBGRA32"] = 2] = "V2LivePixelFormatBGRA32"; V2LivePixelFormat[V2LivePixelFormat["V2LivePixelFormatRGBA32"] = 3] = "V2LivePixelFormatRGBA32"; })(V2LivePixelFormat = exports.V2LivePixelFormat || (exports.V2LivePixelFormat = {})); /** * 视频数据包装格式 * * @enum {Number} */ const V2LiveBufferType_HACK_JSDOC = { /** 未知。*/ V2LiveBufferTypeUnknown: 0, /** 二进制Buffer类型。*/ V2LiveBufferTypeByteBuffer: 1, }; var V2LiveBufferType; (function (V2LiveBufferType) { V2LiveBufferType[V2LiveBufferType["V2LiveBufferTypeUnknown"] = 0] = "V2LiveBufferTypeUnknown"; V2LiveBufferType[V2LiveBufferType["V2LiveBufferTypeByteBuffer"] = 1] = "V2LiveBufferTypeByteBuffer"; })(V2LiveBufferType = exports.V2LiveBufferType || (exports.V2LiveBufferType = {})); ///////////////////////////////////////////////////////////////////////////////// // // (二)音频相关类型定义 // ///////////////////////////////////////////////////////////////////////////////// /** * 声音音质 * * @enum {Number} */ const V2LiveAudioQuality_HACK_JSDOC = { /** 语音音质:采样率:16k;单声道;音频码率:16kbps;适合语音通话为主的场景,比如在线会议,语音通话。*/ V2LiveAudioQualitySpeech: 0, /** 默认音质:采样率:48k;单声道;音频码率:50kbps;SDK 默认的音频质量,如无特殊需求推荐选择之。*/ V2LiveAudioQualityDefault: 1, /** 音乐音质:采样率:48k;双声道 + 全频带;音频码率:128kbps;适合需要高保真传输音乐的场景,比如K歌、音乐直播等。*/ V2LiveAudioQualityMusic: 2, }; var V2LiveAudioQuality; (function (V2LiveAudioQuality) { V2LiveAudioQuality[V2LiveAudioQuality["V2LiveAudioQualitySpeech"] = 0] = "V2LiveAudioQualitySpeech"; V2LiveAudioQuality[V2LiveAudioQuality["V2LiveAudioQualityDefault"] = 1] = "V2LiveAudioQualityDefault"; V2LiveAudioQuality[V2LiveAudioQuality["V2LiveAudioQualityMusic"] = 2] = "V2LiveAudioQualityMusic"; })(V2LiveAudioQuality = exports.V2LiveAudioQuality || (exports.V2LiveAudioQuality = {})); ///////////////////////////////////////////////////////////////////////////////// // // (三)推流器和播放器的一些统计指标数据定义 // ///////////////////////////////////////////////////////////////////////////////// /** * 推流器的统计数据 * * @param {Number} appCpu - 当前 App 的 CPU 使用率(%) * @param {Number} systemCpu - 当前系统的 CPU 使用率(%) * @param {Number} width - 视频宽度 * @param {Number} height - 视频高度 * @param {Number} fps - 帧率(fps) * @param {Number} videoBitrate - 视频码率(Kbps) * @param {Number} audioBitrate - 音频码率(Kbps) * @param {Number} rtt - 从 SDK 到云端的往返延时(ms) * @param {Number} netSpeed - 上行速度(kbps) */ class V2LivePusherStatistics { constructor(appCpu = 0, systemCpu = 0, width = 0, height = 0, fps = 0, videoBitrate = 0, audioBitrate = 0, rtt = 0, netSpeed = 0) { this.appCpu = appCpu; this.systemCpu = systemCpu; this.width = width; this.height = height; this.fps = fps; this.videoBitrate = videoBitrate; this.audioBitrate = audioBitrate; this.rtt = rtt; this.netSpeed = netSpeed; } } exports.V2LivePusherStatistics = V2LivePusherStatistics; ///////////////////////////////////////////////////////////////////////////////// // // (四)连接状态相关枚举值定义 // ///////////////////////////////////////////////////////////////////////////////// /** * 直播流的连接状态 * * @enum {Number} */ const V2LivePushStatus_HACK_JSDOC = { /** 与服务器断开连接。 */ V2LivePushStatusDisconnected: 0, /** 正在连接服务器。 */ TRTCPublishBigStreamToCdn: 1, /** 连接服务器成功。 */ V2LivePushStatusConnectSuccess: 2, /** 重连服务器中。 */ V2LivePushStatusReconnecting: 3, }; var V2LivePushStatus; (function (V2LivePushStatus) { V2LivePushStatus[V2LivePushStatus["V2LivePushStatusDisconnected"] = 0] = "V2LivePushStatusDisconnected"; V2LivePushStatus[V2LivePushStatus["V2LivePushStatusConnecting"] = 1] = "V2LivePushStatusConnecting"; V2LivePushStatus[V2LivePushStatus["V2LivePushStatusConnectSuccess"] = 2] = "V2LivePushStatusConnectSuccess"; V2LivePushStatus[V2LivePushStatus["V2LivePushStatusReconnecting"] = 3] = "V2LivePushStatusReconnecting"; })(V2LivePushStatus = exports.V2LivePushStatus || (exports.V2LivePushStatus = {}));