以Promise风格调用: 不支持
监听 WebSocket 接受到服务器的消息事件
function callback
属性 | 类型 | 说明 |
---|---|---|
data | string,arraybuffer | 服务器返回的消息 |
// 监听 WebSocket 接收到服务器消息事件 xhs.onSocketMessage((res) => { console.log('收到服务器消息:', res.data); // 判断消息类型并处理 if (typeof res.data === 'string') { console.log('收到文本消息:', res.data); } else if (res.data instanceof ArrayBuffer) { console.log('收到二进制消息:', new Uint8Array(res.data)); } });