TCGSDK

云渲染JSSDK(TCGSDK),用于云渲染 PaaS 应用的开发。TCGSDK export 为单例,采用注册回调方式,并提供了包括鼠标键盘控制,音视频控制,游戏进程控制相关接口,接口详情请参考下列说明。

Methods

init(config) → {void}

Parameters:
Name Type Description
config InitConfig

TCGSDK 入口文件,TCGSDK 其他方法建议在 init 的回调函数 onInitSuccess/onConnectSuccess 中调用

Returns:
Type
void

getInitOptions() → {InitConfig}

获取初始化参数 InitConfig

Returns:
Type
InitConfig

getClientSession() → {string}

获取 Client 端会话信息

ClientSession 在每次 init 生命周期可用,当 destroy 后,需要重新 init,再获取最新 ClientSession

Example
const clientSession = TCGSDK.getClientSession();
Returns:
Type
string

start(serverSession) → {void}

启动云渲染

Example
TCGSDK.start(serverSession);
Parameters:
Name Type Description
serverSession string

调用云API接口 CreateSession 后返回的 ServerSession

Returns:
Type
void

destroy(paramsopt) → {void}

立即停止云渲染;

该接口为前端的停止,即 clear 当前的连接(peerConnection)。云端会在自动检测到心跳消失后,释放资源。

如需立即释放云端资源,云游戏请调用云API StopGame,应用云渲染请调用云API DestroySession

Example
TCGSDK.destroy();
Parameters:
Name Type Attributes Description
params Object <optional>
Properties
Name Type Attributes Default Description
code number <optional>
0
message string <optional>
''
Returns:
Type
void

reconnect() → {void}

重连接口,也可以设置 init reconnect 参数由SDK 自动调用。或根据 onDisconnect 回调 code,结合自身场景,主动调用该接口

重连策略:每5秒尝试一次,最多重连5次

Example
TCGSDK.reconnect();
Returns:
Type
void

getIsMobileGame() → {boolean}

获取是否为手游方案

Example
TCGSDK.getIsMobileGame();
Returns:
Type
boolean

reshapeWindow() → {void}

重新调整video 位置

视图根据云端分辨率比例,采用短边适配原则,如未达到预期,可通过该接口重新调整视图,或直接通过 CSS 样式覆盖。

Example
TCGSDK.reshapeWindow();
Returns:
Type
void

setPageBackground(url) → {void}

设置云渲染页面的背景图。 注意,这里设置的是前端container 的背景图,不是云端的背景图,云端背景图通过createSession 设置

Parameters:
Name Type Description
url string

背景图片

Returns:
Type
void

setFullscreen(fullscreen, element) → {Promise.<void>}

设置是否全屏

iOS 不可用

Example
TCGSDK.setFullscreen(true, html);
Parameters:
Name Type Description
fullscreen boolean

是全屏还是退出全屏

element HTMLElement

需要操作的节点

Returns:
Type
Promise.<void>

getFullscreen() → {boolean}

获取是否全屏

Returns:
Type
boolean

getPageOrientation() → {'portrait'|'landscape'}

获取页面方向

Returns:
Type
'portrait' | 'landscape'

getRequestId() → {string}

获取当前连接 requestId

在调用 TCGSDK.start() 后生效

Returns:
Type
string

gameRestart(callbackopt) → {void}

重启当前运行的游戏进程

Parameters:
Name Type Attributes Description
callback function <optional>
Returns:
Type
void

gamePause(callbackopt) → {void}

暂停当前运行的游戏进程

Parameters:
Name Type Attributes Description
callback function <optional>
Returns:
Type
void

gameResume(callbackopt) → {void}

恢复运行当前运行的游戏进程

Parameters:
Name Type Attributes Description
callback function <optional>
Returns:
Type
void

sendText(content, callbackopt) → {void}

聚焦输入框时快速发送内容

Example
TCGSDK.sendText('abc');
Parameters:
Name Type Attributes Description
content string

需要发送的内容

callback function <optional>

回调 code: 0 success, 1 failed

Returns:
Type
void

setClientInteractMode(mode) → {void}

设置云端应用交互模式,也可通过 InitConfig clientInteractMode 设置

该参数建议移动端使用,PC 端设置该参数会导致鼠标锁定

Example
TCGSDK.setClientInteractMode('cursor');
Parameters:
Name Type Default Description
mode string 'cursor'

'cursor' 表示鼠标,‘touch’ 表示触控,需要云上应用支持

Returns:
Type
void

(async) setRemoteDesktopResolution(param) → {Promise.<{code: (0|1)}>}

设置云端桌面分辨率 width、height

建议在 onConnectSuccess 内调用

云上应用大概可以分为以下四种模式

  1. 有边框窗口 - 应用有边框,类似文件夹浏览器的窗口,打开应用的同时可以看到桌面
  2. 无边框窗口 - 应用无边框,应用分辨率小于桌面分辨率,看不到标题栏之类的状态条,打开应用的同时可以看到桌面
  3. 无边框全屏 - 应用无边框且应用分辨率等同于桌面分辨率,桌面被应用完全遮挡,达到全屏的效果
  4. 独占全屏 - 应用独占全屏,显示器分辨率由应用控制,此时强行修改桌面分辨率可能导致应用崩溃

区分无边框全屏和独占全屏 -无边框全屏的应用按alt tab切换窗口不会导致显示器闪烁,独占全屏应用会有个闪烁的现象-

以上四种模式除4(独占全屏)模式外,都能使用该接口

Example
TCGSDK.setRemoteDesktopResolution({width: 1920, height: 1080});
Parameters:
Name Type Description
param Object
Properties
Name Type Description
width number

云端桌面宽度

height number

云端桌面高度

Returns:

返回 Promise 对象。 0 成功 1 失败

Type
Promise.<{code: (0|1)}>

getRemoteStreamResolution() → {Object}

获取视频流的分辨率

Example
const {width, height} = TCGSDK.getRemoteStreamResolution();
Returns:

Object {width: number; height: number}

Type
Object

(async) createCustomDataChannel(param)

创建自定义dataChannel,建议在onConnectSuccess 回调中使用,请求参数具体如下:

建议在 onConnectSuccess 内 setTimeout 调用

常见问题

  • 数据通道创建成功,业务前端发送数据成功,但没有收到云端应用回复的数据

    参考流程

    1. 该接口调用成功表示业务前端与云端数据通道已建立成功,但可能此时云端应用并未完全拉起,业务前端可以通过 timeout/interval/轮询等形式发送自定义数据,确保云端应用成功拉起后正常接收到业务前端发送的自定义数据。只要数据通道创建成功,默认数据能发送成功。
    2. 在onMessage 回调中确定收到云端应用数据,可以取消轮询,之后正常发送数据。
  • 可以收发的数据类型

    该接口支持 string | ArrayBuffer

  • 数据包传输大小是否有限制

    服务对传输数据包大小没有限制,但是需要注意 UDP 最大包长是 64KB,建议包大小应该小于 MTU 1500。如果包体过大,建议通过分包形式传输,如果太多数据上行容易导致拥塞影响体验。

Example
let timer = null;

const { sendMessage, code } = await TCGSDK.createCustomDataChannel({
  destPort: 10005,
  onMessage: (res) => {
    console.log('CustomDataChannel onMessage', res);

    // 收到该回调后,表示云端应用已成功拉起并收到数据,可以 clearInterval,之后正常发送数据
    // clearInterval(timer)
  },
});

// code 为 0表示,web 端与云端数据通道已建立成功,但此时可能云端应用并未完全拉起,web 端可以通过 setTimeout/setInterval/轮询发送消息
if (code === 0) {
  // 发送自定义消息
  sendMessage('abc123');

  // timer = setInterval(() => {
  //   sendMessage('abc123');
  // }, 5000);
}

if (code === 1) {
  // 考虑重新创建数据通道
}
Parameters:
Name Type Description
param Object
Properties
Name Type Attributes Default Description
destPort number

目标端口,端口范围建议为 10000-20000

protocol string <optional>
'text'

'text' | 'binary',指定云端回复(onMessage 方法内收到的)数据类型

onMessage function

dataChannel收到消息的回调函数

Returns:

返回 Promise 对象。

Name Type Description
code number 0 success, 1 ack dataChannel 未创建成功,请重试, 2 该数据通道已经存在, 3 请求超时,请重试, -1 创建失败(ack 返回)
msg string
sendMessage (message: string | Blob | ArrayBuffer | ArrayBufferView) => void; 用于发送消息的方法,会透传数据给 peerConnection 的 dataChannel,参数message 支持 RTCDataChannel send 所有数据类型

sendKeyboardEvent(param) → {void}

发送键盘事件,该方法调用通常是成对出现(就像正常打字,通常是down/up组合)

键盘的键位码 可通过 keycode 查询

对于云手游常用按键keycode是: KEY_BACK = 158 KEY_MENU = 139 KEY_HOME = 172

Example
// 按下时
TCGSDK.sendKeyboardEvent({key: 32, down: true});
// 抬起时
TCGSDK.sendKeyboardEvent({key: 32, down:  false});
Parameters:
Name Type Description
param Object
Properties
Name Type Description
key number

对应的 code 码

down boolean

是否是按下状态

location number

1 左键,2 右键

Returns:
Type
void

sendMouseEvent(param) → {void}

发送鼠标事件

Example
// 鼠标左键按下
TCGSDK.sendMouseEvent({type: 'mouseleft', down: true});
// 鼠标左键抬起
TCGSDK.sendMouseEvent({type: 'mouseleft', down: false});
Parameters:
Name Type Description
param Object
Properties
Name Type Attributes Description
type MouseEvent

鼠标事件类型 'mouseleft' | 'mouseright' | 'mousemiddle' | 'mouseforward' | 'mousebackward' | 'mousescroll' | 'mousemove' | 'mousedeltamove'

down boolean <optional>

是否是按下状态(就像正常鼠标点击,通常是down/up组合)

delta number <optional>

鼠标滚轮,通常传 1/-1

Returns:
Type
void

sendGamepadEvent(param) → {void}

发送手柄事件

对于PC 端(如果浏览器支持 Gamepad API),TCGSDK 已自动监听/处理了手柄事件,无需手动调用

Example
// 连接手柄
TCGSDK.sendGamepadEvent({ type: 'gamepadconnect' });
// 断开手柄
TCGSDK.sendGamepadEvent({ type: 'gamepaddisconnect' });
// key X 按下
TCGSDK.sendGamepadEvent({ type: 'gamepadkey', key: '0x4000', down: true });
// lt
TCGSDK.sendGamepadEvent({ type: 'lt', x:  200, down: true });
// axisleft
TCGSDK.sendGamepadEvent({ type: 'axisleft', x: 10000, y: -10000 });
Parameters:
Name Type Description
param Object
Properties
Name Type Attributes Description
type GamePadEvent

手柄事件类型 'gamepadconnect' | 'gamepaddisconnect' | 'gamepadkey' | 'axisleft' | 'axisright' | 'lt' | 'rt'

down boolean <optional>

是否是按下状态

key number <optional>

手柄键值

• 方向键事件值:向上键值为0x01,向下键值为0x02,向左键值为0x04,向右键值为0x08

• 按键事件值:X 键值为0x4000,Y 键值为0x8000,A 键值为0x1000, B键值为0x2000

•select 事件值:键值为0x20

•start 事件值:键值为0x10

x number <optional>

lt/rt 取值[0-255], axisleft/axisright [-32767~32767]

y number <optional>

针对 axisleft/axisright [-32767~32767]

Returns:
Type
void

sendRawEvent(params) → {void}

Deprecated:
  • Yes

发送鼠标及键盘事件(底层实现 ACK 通道)

Parameters:
Name Type Description
params RawEventData

底层原始数据类型,可用于鼠标/键盘/手柄消息的发送

Returns:
Type
void

sendSeqRawEvents(params) → {void}

Deprecated:
  • Yes

发送按键序列(底层实现)

Parameters:
Name Type Description
params Array.<RawEventData>

序列化发送数据

Returns:
Type
void

setMoveSensitivity(value) → {void}

设置鼠标移动灵敏度

该方法只针对 deltaMove 生效

Parameters:
Name Type Description
value number

取值范围:[0.01, 100.0]之间的浮点数

Returns:
Type
void

getMoveSensitivity() → {number}

获取当前鼠标灵敏度值

Returns:
Type
number

mouseMove(identifier, type, x, y) → {void}

模拟鼠标移动

Example
TCGSDK.mouseMove(id: 1, type: 'touchstart', pageX: 100, pageY: 100);
Parameters:
Name Type Description
identifier number

触控点的 ID,多点触控时每个触控点 ID不能相等,同个触控点的所有事件的触控点 ID 必须一致

type TouchType

触控事件类型,值为touchstart、touchmove、touchend、touchcancel中的一个,对于同一个触控点,touchstart 必须且只对应一个 touchend 或 touchcancel

x number

触控点的 x 坐标,但是如果传浮点数,则按逻辑坐标处理

y number

触控点的 y 坐标,但是如果传浮点数,则按逻辑坐标处理

Returns:
Type
void

mouseTabletMode(param) → {void}

开启或关闭滑屏鼠标移动模式,通常对于鼠标相对位移方式

该方法只针对移动端适用。该 mode 下鼠标产生相对位移。

Parameters:
Name Type Description
param boolean

true:打开,false:关闭

Returns:
Type
void

setRemoteCursor(mode) → {void}

设置鼠标模式

该方法建议在PC 端使用

Parameters:
Name Type Description
mode number

目前支持三种鼠标样式:

mode=0:页面渲染的固定鼠标图片,如未设置默认鼠标图片,会采用系统鼠标

mode=1:采用云端应用内的鼠标图片,图片会下发到前端,由前端在浏览器页面绘制

mode=2:(不建议使用)云端画面内渲染鼠标图片,此时会隐藏本地渲染的鼠标,兼容性最好,但是有延时

Returns:
Type
void

setCursorStatus(status) → {void}

设置鼠标状态,用于强制显示/强制锁定/自动跟随云端应用显示或锁定鼠标

Parameters:
Name Type Description
status string

目前支持三种状态

status='forceShow' 强制网页鼠标显示鼠标

status='forceLock' 强制锁定网页鼠标

status='auto' 自动跟随云端应用的鼠标状态,如云端应用显示鼠标则网页显示鼠标,云端应用隐藏鼠标则网页锁定鼠标

Returns:
Type
void

setCursorShowStat(show) → {void}

(不建议使用) 如果鼠标显示/锁定需求调用 setCursorStatus

设置鼠标隐藏或显示

但是云端下发的鼠标显隐会覆盖掉该设置

Parameters:
Name Type Description
show boolean
Returns:
Type
void

getCursorShowStat() → {boolean}

获取云端鼠标隐藏状态,true|false

Returns:
Type
boolean

setMouseCanLock(param) → {void}

设置是否允许锁定鼠标,该接口适用于云端应用会下发锁定鼠标指令,这里设置成 false会强制显示鼠标

Parameters:
Name Type Default Description
param boolean true

其中 true 为允许,false 为禁止。默认为 true。

Returns:
Type
void

lockMouse(param) → {void}

强制锁定鼠标

Parameters:
Name Type Default Description
param boolean true

其中 true 为允许,false 为禁止。

Returns:
Type
void

setMobileCursorScale(value) → {void}

移动端适用,设置虚拟鼠标放大系数

Parameters:
Name Type Description
value number

放大系数,默认是1.0,与云端大小一致,取值范围[0.1,10]

Returns:
Type
void

clearRemoteKeys() → {void}

重置云端所有按键状态,用于云端按键卡住的场景。

Returns:
Type
void

resetRemoteCapsLock() → {void}

重置云端大小写状态为小写。

Returns:
Type
void

setDefaultCursorImage(url) → {void}

设置云渲染页面中鼠标默认图片。

Parameters:
Name Type Description
url string

鼠标图片

Returns:
Type
void

setKMStatus(param) → {object}

设置鼠标/键盘的可用状态,针对PC 上,鼠标键盘的对应事件默认会被SDK 捕获然后发向云端

该方法 PC 端适用

Example
TCGSDK.setKMStatus({keyboard: false, mouse: false});
Parameters:
Name Type Description
param Object
Properties
Name Type Description
keyboard boolean

键盘可用状态

mouse boolean

鼠标可用状态

Returns:
Type
object

setPaste(enable) → {void}

设置是否劫持 Ctrl+v/Cmd+v,当用户使用粘贴功能时候,直接将本地剪切板内容发送给云端

该方法PC 端适用,通常在云端 input 框 focus 时候使用

Parameters:
Name Type Description
enable boolean
Returns:
Type
void

setStreamProfile(profile, callbackopt) → {void}

Deprecated:
  • Yes

设置码流参数,该接口为设置建议码流参数,云端可能会根据游戏动态调整

如果CreateSession 参数中设置了 MinBitrate/MaxBitrate,参数 min_bitrate/max_bitrate 必须在前者设置范围内

Example
TCGSDK.setStreamProfile({ fps: 60, max_bitrate: 8, min_bitrate: 5 });
Parameters:
Name Type Attributes Description
profile Object

目前可用参数如下:

Properties
Name Type Description
fps number

帧率,范围[10,60]

max_bitrate number

最大码率,范围[1,15],单位:Mbps

min_bitrate number

最小码率,范围[1,15],单位:Mbps

callback function <optional>

设置结果回调函数,可为 null

Returns:
Type
void

getDisplayRect()

获取显示区域的参数,边距,宽高等,具体参数如下:

Returns:

返回 video 通过 getBoundingClientRect 获取的数据

Name Type Description
left number 相对视图窗口 left 值
top number 相对视图窗口 top 值
width number 播放元素(video)width
height number 播放元素(video)height
pixelRatio number window.devicePixelRatio 当前显示设备的物理像素分辨率与CSS 像素分辨率之比

setVideoVolume(value) → {void}

设置video 音量

Example
TCGSDK.setVideoVolume(0);
Parameters:
Name Type Description
value number

number [0-1]

Returns:
Type
void

getVideoVolume() → {number}

获取video 音量

Returns:
Type
number

playVideo(status) → {void|Promise.<void>}

播放视频

  • 'play' 其实是调用了 video 的 play, 返回 Promise*
Example
TCGSDK.playVideo('play');
Parameters:
Name Type Description
status 'play' | 'pause'
Returns:
Type
void | Promise.<void>

getVideoElement() → {HTMLVideoElement}

获取 video 对象

Example
TCGSDK.getVideoElement();
Returns:
Type
HTMLVideoElement

getUserMedia() → {MediaStream}

获取用户开启的摄像头或麦克风 stream

Returns:
Type
MediaStream

switchMic(param) → {Promise.<Object>}

开关麦克风

Example
TCGSDK.switchMic({status: 'open'});
Parameters:
Name Type Description
param Object
Properties
Name Type Attributes Description
status 'open' | 'close'

开关状态

profile boolean | MicProfileConstraints <optional>

麦克风设置

Returns:

结构如下

Response Type Description
code 0 or 1 0 success 1 failed
msg string message
userMedia MediaStream 获取的媒体信息
Type
Promise.<Object>

switchCamera(param) → {Promise.<Object>}

开关摄像头

Example
TCGSDK.switchCamera({status: 'open'});
TCGSDK.switchCamera({status: 'close'});
// 移动端打开后置摄像头
TCGSDK.switchCamera({ status: 'open', profile: { deviceId: 'environment' } });
Parameters:
Name Type Description
param Object
Properties
Name Type Attributes Description
status 'open' | 'close'

开关状态

profile boolean | CameraProfileConstraints | CameraProfileType <optional>

摄像头设置

Returns:

结构如下

Response Type Description
code 0 or 1 0 success 1 failed
msg string message
userMedia MediaStream 获取的媒体信息
Type
Promise.<Object>

(async) setMicProfile(profile) → {Promise.<Object>}

设置麦克风采集质量

Example
TCGSDK.setMicProfile({sampleRate: 44100, echoCancellation: true, noiseSuppression: true, autoGainControl: true});
Parameters:
Name Type Description
profile MicProfileConstraints

MicProfileConstraints 为 Object 具体如下

Properties
Name Type Attributes Default Description
sampleRate number <optional>
44100

采样率 默认值 44100

echoCancellation ConstrainBoolean <optional>
true

回声消除 默认值 true

noiseSuppression ConstrainBoolean <optional>
true

降噪 默认值 true

autoGainControl ConstrainBoolean <optional>
true

增益 默认值 true

deviceId string <optional>

input 的设备id,可以通过 getDevices 接口获取, 默认采用系统自选设备

Returns:

结构如下

Response Type Description
code 0 or 1 0 success 1 failed
msg string message
userMedia MediaStream 获取的媒体信息
Type
Promise.<Object>

(async) setCameraProfile(profile) → {Promise.<Object>}

设置摄像头采集质量

Example
// 根据分辨率设置
TCGSDK.setCameraProfile('720p');
// 个性化设置
TCGSDK.setCameraProfile({width: '1920', height: '1080', frameRate: '60'});
// 移动端切换前后摄像头
TCGSDK.setCameraProfile({ deviceId: 'environment' });
TCGSDK.setCameraProfile({ deviceId: 'user' });
Parameters:
Name Type Description
profile CameraProfileType | CameraProfileConstraints

CameraProfileType = "120p" | "180p" | "240p" | "360p" | "480p" | "720p" | "1080p"

CameraProfileConstraints 为 Object 具体如下

Properties
Name Type Attributes Default Description
width number <optional>
1280

宽 默认值 1280

height number <optional>
720

高 默认值 720

frameRate number <optional>
30

帧率 默认值 30

bitrate number <optional>
1500

码率 1500 kbps

deviceId string <optional>

input 的设备id,可以通过 getDevices 接口获取, 默认采用系统自选设备。移动端可传入 'user' | 'environment', 来区前置/后置摄像头

Returns:

结构如下

Response Type Description
code 0 or 1 0 success 1 failed
msg string message
userMedia MediaStream 获取的媒体信息
Type
Promise.<Object>

(async) getDevices() → {Array.<MediaDeviceInfo>}

获取所有设备

Returns:
Type
Array.<MediaDeviceInfo>

setVideoOrientation(param) → {void}

设置video 的旋转角度。

发现有时候客户会自己旋转屏幕,其实不建议。因为涉及到的坐标转换很复杂,SDK 内部已经处理。连同插件的旋转和数据处理都在SDK 内部做了。建议用该方法,或者直接在 Init 参数重配置自动旋转

Example
// 旋转 HTML 文档
TCGSDK.setVideoOrientation({ deg: 90, rotateContainer: true });
// 旋转 MountPoint
TCGSDK.setVideoOrientation({ deg: 90, rotateMountPoint: true });
Parameters:
Name Type Description
param Object
Properties
Name Type Attributes Default Description
deg 0 | 90 | 270 0

旋转角度当前只支持 0/90,手游 0/270

rotateContainer boolean <optional>
true

是否旋转整个html 视图,默认值true

rotateMountPoint boolean <optional>
false

是否旋转mountPoint 节点,默认值false

Returns:
Type
void

getPageSize() → {Object}

获取页面尺寸

可获取根据设备 window.devicePixelRatio 乘以固定比例保证显示画面分辨率足够清晰

Example
const {width, height} = TCGSDK.getPageSize();
Returns:

{ width: number; height: number };

Type
Object

setDebugMode(param) → {void}

打开或关闭调试模式,打开的情况下将在控制台打印日志。也可以通过 Init 参数设置。

Example
TCGSDK.setDebugMode({showLog: true, showStats: true});
Parameters:
Name Type Description
param Object
Properties
Name Type Attributes Description
showLog boolean <optional>

打印SDK 所有日志

showStats boolean <optional>

展示数据面板 webrtc 状态信息,否则需要按 CTRL+~ 快捷键显示。

showSendKmData boolean <optional>

打印键盘/鼠标键入的消息

showSendAckData boolean <optional>

打印发送的ACK message

showSendHbData boolean <optional>

打印发送的Hb message

showOnHbMessage boolean <optional>

打印心跳回包消息

showOnKmMessage boolean <optional>

打印km回包消息

showOnAckMessage boolean <optional>

打印ACK回包消息

showOnCdMessage boolean <optional>

打印CD回包消息

showOnSvMessage boolean <optional>

打印Sv回包消息

Returns:
Type
void

reportLog() → {Object}

上报日志

Returns:

{ code: number; message: string } code=0 success code=-1 failed

Type
Object

setLogHandler(handler) → {void}

设置日志回调函数,便于外部获取详细日志,作用与 init 时传的 onLog 回调一致。

Parameters:
Name Type Description
handler function
Returns:
Type
void

toggleMetricReportBulk(start) → {void}

性能数据上报开关

Parameters:
Name Type Description
start boolean
Returns:
Type
void

getPlayerVolume(id) → {number}

获取对应玩家 音量

Parameters:
Name Type Description
id string

用户id

Returns:
Type
number

setPlayerVolume(id, val) → {number}

设置对应玩家 音量

Parameters:
Name Type Description
id string

用户id

val number

音量 [0-1]

Returns:
Type
number

getSeats() → {Promise.<SeatsInfo>}

获取所有坐席

Returns:

返回 Promise 对象。

Type
Promise.<SeatsInfo>

submitSeatChange(param) → {Promise.<{code: number}>}

申请切换角色或席位(非主机玩家),返回code及描述如下:

Parameters:
Name Type Description
param Object
Properties
Name Type Description
user_id string

用户 id

to_role 'viewer' | 'player'

需要切换的角色

seat_index number

座位号

Returns:

返回 Promise<{ code: number }>; Code 如下

Code Description
0 Success
1001 MultiPlayerInvalidSeatIndex
1002 MultiPlayerNoAuthorized
1003 MultiPlayerNoSuchRole
1004 MultiPlayerNoSuchUser
1005 MultiPlayerAssignSeatFailed
1006 MultiPlayerJsonParseFailed
1007 MultiPlayerIgnoredHostSubmit
Type
Promise.<{code: number}>

seatChange(param) → {Promise.<{code: number}>}

只有主机玩家才能调用该接口,返回code及描述如下:

Parameters:
Name Type Description
param Object
Properties
Name Type Description
user_id string

用户 id

to_role 'viewer' | 'player'

需要切换的角色

seat_index number

座位号

Returns:

返回 Promise<{ code: number }>; Code 如下

Code Description
0 Success
1001 MultiPlayerInvalidSeatIndex
1002 MultiPlayerNoAuthorized
1003 MultiPlayerNoSuchRole
1004 MultiPlayerNoSuchUser
1005 MultiPlayerAssignSeatFailed
1006 MultiPlayerJsonParseFailed
1007 MultiPlayerIgnoredHostSubmit
Type
Promise.<{code: number}>

changeMicStatus(param) → {Promise.<ChangeMicStatusResponse>}

切换麦克风状态

Parameters:
Name Type Description
param Object
Properties
Name Type Description
status string

1:主动闭麦 2: 开麦

user_id string

用户 id

Returns:

返回 ChangeMicStatusResponse类型如下:

Response Type Description
type string mic_status (0 ==> Success ; -2 ==> NoAuthorized ; -4 ==> NoSuchUser)
code number 0 ==> 管理员禁麦 ; 1 ==> 主动闭麦 ; 2 ==> 开麦
status number status (非必须)
user_id string user_id (非必须)
Type
Promise.<ChangeMicStatusResponse>