mirror of
https://github.com/Megghy/vtsuru.live.git
synced 2025-12-07 02:46:55 +08:00
feat: 更新依赖和移除不必要的文件, 更新歌单管理列表在小屏幕上的显示效果, 修复自定义配置文件加载
- 在 package.json 中移除不再使用的依赖项,并更新部分依赖版本 - 删除多个不再使用的组件和文件,包括 CheckInTemplateHelper.vue、CommonConfigItems.vue、GlobalSettingsConfig.vue 等 - 更新 bun.lockb 文件以反映依赖变更
This commit is contained in:
@@ -1 +0,0 @@
|
||||
import EasySpeech from 'easy-speech'
|
||||
@@ -1,154 +0,0 @@
|
||||
import ChatClientOfficialBase, * as base from './ChatClientOfficialBase'
|
||||
import { processAvatarUrl } from './models'
|
||||
|
||||
export default class ChatClientDirectOpenLive extends ChatClientOfficialBase {
|
||||
constructor(authInfo) {
|
||||
super()
|
||||
this.CMD_CALLBACK_MAP = CMD_CALLBACK_MAP
|
||||
|
||||
this.auth = authInfo
|
||||
}
|
||||
|
||||
stop() {
|
||||
super.stop()
|
||||
}
|
||||
|
||||
async initRoom() {
|
||||
return true
|
||||
}
|
||||
|
||||
async onBeforeWsConnect() {
|
||||
return super.onBeforeWsConnect()
|
||||
}
|
||||
|
||||
getWsUrl() {
|
||||
return this.auth.websocket_info.wss_link[this.retryCount % this.auth.websocket_info.wss_link.length]
|
||||
}
|
||||
|
||||
sendAuth() {
|
||||
this.websocket.send(this.makePacket(this.auth.websocket_info.auth_body, base.OP_AUTH))
|
||||
}
|
||||
|
||||
async dmCallback(command) {
|
||||
if (!this.onAddText) {
|
||||
return
|
||||
}
|
||||
let data = command.data
|
||||
|
||||
let authorType
|
||||
if (data.uid === this.roomOwnerUid) {
|
||||
authorType = 3
|
||||
} else if (data.guard_level !== 0) {
|
||||
authorType = 1
|
||||
} else {
|
||||
authorType = 0
|
||||
}
|
||||
|
||||
let emoticon = null
|
||||
if (data.dm_type === 1) {
|
||||
emoticon = data.emoji_img_url
|
||||
}
|
||||
|
||||
data = {
|
||||
avatarUrl: processAvatarUrl(data.uface),
|
||||
timestamp: data.timestamp,
|
||||
authorName: data.uname,
|
||||
authorType: authorType,
|
||||
content: data.msg,
|
||||
privilegeType: data.guard_level,
|
||||
isGiftDanmaku: false,
|
||||
authorLevel: 1,
|
||||
isNewbie: false,
|
||||
isMobileVerified: true,
|
||||
medalLevel: data.fans_medal_wearing_status ? data.fans_medal_level : 0,
|
||||
id: data.msg_id,
|
||||
translation: '',
|
||||
emoticon: emoticon,
|
||||
}
|
||||
this.onAddText(data)
|
||||
}
|
||||
|
||||
sendGiftCallback(command) {
|
||||
if (!this.onAddGift) {
|
||||
return
|
||||
}
|
||||
let data = command.data
|
||||
if (!data.paid) {
|
||||
// 丢人
|
||||
return
|
||||
}
|
||||
|
||||
data = {
|
||||
id: data.msg_id,
|
||||
avatarUrl: processAvatarUrl(data.uface),
|
||||
timestamp: data.timestamp,
|
||||
authorName: data.uname,
|
||||
totalCoin: data.price,
|
||||
giftName: data.gift_name,
|
||||
num: data.gift_num,
|
||||
}
|
||||
this.onAddGift(data)
|
||||
}
|
||||
|
||||
async guardCallback(command) {
|
||||
if (!this.onAddMember) {
|
||||
return
|
||||
}
|
||||
|
||||
let data = command.data
|
||||
data = {
|
||||
id: data.msg_id,
|
||||
avatarUrl: processAvatarUrl(data.user_info.uface),
|
||||
timestamp: data.timestamp,
|
||||
authorName: data.user_info.uname,
|
||||
privilegeType: data.guard_level,
|
||||
}
|
||||
this.onAddMember(data)
|
||||
}
|
||||
|
||||
superChatCallback(command) {
|
||||
if (!this.onAddSuperChat) {
|
||||
return
|
||||
}
|
||||
|
||||
let data = command.data
|
||||
data = {
|
||||
id: data.message_id.toString(),
|
||||
avatarUrl: processAvatarUrl(data.uface),
|
||||
timestamp: data.start_time,
|
||||
authorName: data.uname,
|
||||
price: data.rmb,
|
||||
content: data.message,
|
||||
translation: '',
|
||||
}
|
||||
this.onAddSuperChat(data)
|
||||
}
|
||||
|
||||
superChatDelCallback(command) {
|
||||
if (!this.onDelSuperChat) {
|
||||
return
|
||||
}
|
||||
|
||||
const ids = []
|
||||
for (const id of command.data.message_ids) {
|
||||
ids.push(id.toString())
|
||||
}
|
||||
this.onDelSuperChat({ ids })
|
||||
}
|
||||
|
||||
rawMessageCallback(command) {
|
||||
if (!this.onRawMessage) {
|
||||
return
|
||||
}
|
||||
this.onRawMessage(command)
|
||||
}
|
||||
}
|
||||
|
||||
const CMD_CALLBACK_MAP = {
|
||||
LIVE_OPEN_PLATFORM_DM: ChatClientDirectOpenLive.prototype.dmCallback,
|
||||
LIVE_OPEN_PLATFORM_SEND_GIFT: ChatClientDirectOpenLive.prototype.sendGiftCallback,
|
||||
LIVE_OPEN_PLATFORM_GUARD: ChatClientDirectOpenLive.prototype.guardCallback,
|
||||
LIVE_OPEN_PLATFORM_SUPER_CHAT: ChatClientDirectOpenLive.prototype.superChatCallback,
|
||||
LIVE_OPEN_PLATFORM_SUPER_CHAT_DEL: ChatClientDirectOpenLive.prototype.superChatDelCallback,
|
||||
RAW_MESSAGE: ChatClientDirectOpenLive.prototype.rawMessageCallback,
|
||||
}
|
||||
@@ -1,176 +0,0 @@
|
||||
import * as chat from './ChatClientOfficialBase'
|
||||
import * as chatModels from './models.js'
|
||||
import * as base from './ChatClientOfficialBase'
|
||||
import ChatClientOfficialBase from './ChatClientOfficialBase'
|
||||
|
||||
export default class ChatClientDirectWeb extends ChatClientOfficialBase {
|
||||
constructor(roomId) {
|
||||
super()
|
||||
this.CMD_CALLBACK_MAP = CMD_CALLBACK_MAP
|
||||
|
||||
// 调用initRoom后初始化,如果失败,使用这里的默认值
|
||||
this.roomId = roomId
|
||||
this.roomOwnerUid = -1
|
||||
this.hostServerList = [
|
||||
{
|
||||
host: 'broadcastlv.chat.bilibili.com',
|
||||
port: 2243,
|
||||
wss_port: 443,
|
||||
ws_port: 2244
|
||||
}
|
||||
]
|
||||
this.hostServerToken = null
|
||||
this.buvid = ''
|
||||
}
|
||||
|
||||
async initRoom() {
|
||||
let res
|
||||
try {
|
||||
res = await (
|
||||
await fetch('/api/room_info?room_id=' + this.roomId, { method: 'GET' })
|
||||
).json()
|
||||
} catch {
|
||||
return true
|
||||
}
|
||||
this.roomId = res.roomId
|
||||
this.roomOwnerUid = res.ownerUid
|
||||
if (res.hostServerList.length !== 0) {
|
||||
this.hostServerList = res.hostServerList
|
||||
}
|
||||
this.hostServerToken = res.hostServerToken
|
||||
this.buvid = res.buvid
|
||||
return true
|
||||
}
|
||||
|
||||
async onBeforeWsConnect() {
|
||||
// 重连次数太多则重新init_room,保险
|
||||
let reinitPeriod = Math.max(3, (this.hostServerList || []).length)
|
||||
if (this.retryCount > 0 && this.retryCount % reinitPeriod === 0) {
|
||||
this.needInitRoom = true
|
||||
}
|
||||
return super.onBeforeWsConnect()
|
||||
}
|
||||
|
||||
getWsUrl() {
|
||||
let hostServer =
|
||||
this.hostServerList[this.retryCount % this.hostServerList.length]
|
||||
return `wss://${hostServer.host}:${hostServer.wss_port}/sub`
|
||||
}
|
||||
|
||||
sendAuth() {
|
||||
let authParams = {
|
||||
uid: 0,
|
||||
roomid: this.roomId,
|
||||
protover: 3,
|
||||
platform: 'web',
|
||||
type: 2,
|
||||
buvid: this.buvid
|
||||
}
|
||||
if (this.hostServerToken !== null) {
|
||||
authParams.key = this.hostServerToken
|
||||
}
|
||||
this.websocket.send(this.makePacket(authParams, base.OP_AUTH))
|
||||
}
|
||||
|
||||
async danmuMsgCallback(command) {
|
||||
let info = command.info
|
||||
|
||||
let roomId, medalLevel
|
||||
if (info[3]) {
|
||||
roomId = info[3][3]
|
||||
medalLevel = info[3][0]
|
||||
} else {
|
||||
roomId = medalLevel = 0
|
||||
}
|
||||
|
||||
let uid = info[2][0]
|
||||
let isAdmin = info[2][2]
|
||||
let privilegeType = info[7]
|
||||
let authorType
|
||||
if (uid === this.roomOwnerUid) {
|
||||
authorType = 3
|
||||
} else if (isAdmin) {
|
||||
authorType = 2
|
||||
} else if (privilegeType !== 0) {
|
||||
authorType = 1
|
||||
} else {
|
||||
authorType = 0
|
||||
}
|
||||
|
||||
let authorName = info[2][1]
|
||||
let content = info[1]
|
||||
let data = new chatModels.AddTextMsg({
|
||||
avatarUrl: await chat.getAvatarUrl(uid, authorName),
|
||||
timestamp: info[0][4] / 1000,
|
||||
authorName: authorName,
|
||||
authorType: authorType,
|
||||
content: content,
|
||||
privilegeType: privilegeType,
|
||||
isGiftDanmaku:
|
||||
Boolean(info[0][9]) || chat.isGiftDanmakuByContent(content),
|
||||
authorLevel: info[4][0],
|
||||
isNewbie: info[2][5] < 10000,
|
||||
isMobileVerified: Boolean(info[2][6]),
|
||||
medalLevel: roomId === this.roomId ? medalLevel : 0,
|
||||
emoticon: info[0][13].url || null
|
||||
})
|
||||
this.msgHandler.onAddText(data)
|
||||
}
|
||||
|
||||
sendGiftCallback(command) {
|
||||
let data = command.data
|
||||
let isPaidGift = data.coin_type === 'gold'
|
||||
data = new chatModels.AddGiftMsg({
|
||||
avatarUrl: chat.processAvatarUrl(data.face),
|
||||
timestamp: data.timestamp,
|
||||
authorName: data.uname,
|
||||
totalCoin: isPaidGift ? data.total_coin : 0,
|
||||
totalFreeCoin: !isPaidGift ? data.total_coin : 0,
|
||||
giftName: data.giftName,
|
||||
num: data.num
|
||||
})
|
||||
this.msgHandler.onAddGift(data)
|
||||
}
|
||||
|
||||
async guardBuyCallback(command) {
|
||||
let data = command.data
|
||||
data = new chatModels.AddMemberMsg({
|
||||
avatarUrl: await chat.getAvatarUrl(data.uid, data.username),
|
||||
timestamp: data.start_time,
|
||||
authorName: data.username,
|
||||
privilegeType: data.guard_level
|
||||
})
|
||||
this.msgHandler.onAddMember(data)
|
||||
}
|
||||
|
||||
superChatMessageCallback(command) {
|
||||
let data = command.data
|
||||
data = new chatModels.AddSuperChatMsg({
|
||||
id: data.id.toString(),
|
||||
avatarUrl: chat.processAvatarUrl(data.user_info.face),
|
||||
timestamp: data.start_time,
|
||||
authorName: data.user_info.uname,
|
||||
price: data.price,
|
||||
content: data.message
|
||||
})
|
||||
this.msgHandler.onAddSuperChat(data)
|
||||
}
|
||||
|
||||
superChatMessageDeleteCallback(command) {
|
||||
let ids = []
|
||||
for (let id of command.data.ids) {
|
||||
ids.push(id.toString())
|
||||
}
|
||||
let data = new chatModels.DelSuperChatMsg({ ids })
|
||||
this.msgHandler.onDelSuperChat(data)
|
||||
}
|
||||
}
|
||||
|
||||
const CMD_CALLBACK_MAP = {
|
||||
DANMU_MSG: ChatClientDirectWeb.prototype.danmuMsgCallback,
|
||||
SEND_GIFT: ChatClientDirectWeb.prototype.sendGiftCallback,
|
||||
GUARD_BUY: ChatClientDirectWeb.prototype.guardBuyCallback,
|
||||
SUPER_CHAT_MESSAGE: ChatClientDirectWeb.prototype.superChatMessageCallback,
|
||||
SUPER_CHAT_MESSAGE_DELETE:
|
||||
ChatClientDirectWeb.prototype.superChatMessageDeleteCallback
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -1,320 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
// @ts-nocheck
|
||||
import { BrotliDecode } from './brotli_decode'
|
||||
import { setInterval, clearInterval, setTimeout, clearTimeout } from 'worker-timers'
|
||||
|
||||
const HEADER_SIZE = 16
|
||||
|
||||
export const WS_BODY_PROTOCOL_VERSION_NORMAL = 0
|
||||
export const WS_BODY_PROTOCOL_VERSION_HEARTBEAT = 1
|
||||
export const WS_BODY_PROTOCOL_VERSION_DEFLATE = 2
|
||||
export const WS_BODY_PROTOCOL_VERSION_BROTLI = 3
|
||||
|
||||
export const OP_HANDSHAKE = 0
|
||||
export const OP_HANDSHAKE_REPLY = 1
|
||||
export const OP_HEARTBEAT = 2
|
||||
export const OP_HEARTBEAT_REPLY = 3
|
||||
export const OP_SEND_MSG = 4
|
||||
export const OP_SEND_MSG_REPLY = 5
|
||||
export const OP_DISCONNECT_REPLY = 6
|
||||
export const OP_AUTH = 7
|
||||
export const OP_AUTH_REPLY = 8
|
||||
export const OP_RAW = 9
|
||||
export const OP_PROTO_READY = 10
|
||||
export const OP_PROTO_FINISH = 11
|
||||
export const OP_CHANGE_ROOM = 12
|
||||
export const OP_CHANGE_ROOM_REPLY = 13
|
||||
export const OP_REGISTER = 14
|
||||
export const OP_REGISTER_REPLY = 15
|
||||
export const OP_UNREGISTER = 16
|
||||
export const OP_UNREGISTER_REPLY = 17
|
||||
// B站业务自定义OP
|
||||
// export const MinBusinessOp = 1000
|
||||
// export const MaxBusinessOp = 10000
|
||||
|
||||
export const AUTH_REPLY_CODE_OK = 0
|
||||
export const AUTH_REPLY_CODE_TOKEN_ERROR = -101
|
||||
|
||||
const HEARTBEAT_INTERVAL = 10 * 1000
|
||||
const RECEIVE_TIMEOUT = HEARTBEAT_INTERVAL + 5 * 1000
|
||||
|
||||
const textEncoder = new TextEncoder()
|
||||
const textDecoder = new TextDecoder()
|
||||
|
||||
export default class ChatClientOfficialBase {
|
||||
constructor() {
|
||||
this.CMD_CALLBACK_MAP = {}
|
||||
|
||||
this.onAddText = null
|
||||
this.onAddGift = null
|
||||
this.onAddMember = null
|
||||
this.onAddSuperChat = null
|
||||
this.onDelSuperChat = null
|
||||
this.onUpdateTranslation = null
|
||||
|
||||
this.onFatalError = null
|
||||
|
||||
this.needInitRoom = true
|
||||
this.websocket = null
|
||||
this.retryCount = 0
|
||||
this.isDestroying = false
|
||||
this.heartbeatTimerId = null
|
||||
this.receiveTimeoutTimerId = null
|
||||
}
|
||||
|
||||
start() {
|
||||
this.wsConnect()
|
||||
}
|
||||
|
||||
stop() {
|
||||
this.isDestroying = true
|
||||
if (this.websocket) {
|
||||
this.websocket.close()
|
||||
}
|
||||
}
|
||||
|
||||
async initRoom() {
|
||||
throw Error('Not implemented')
|
||||
}
|
||||
|
||||
makePacket(data, operation) {
|
||||
let body
|
||||
if (typeof data === 'object') {
|
||||
body = textEncoder.encode(JSON.stringify(data))
|
||||
} else {
|
||||
// string
|
||||
body = textEncoder.encode(data)
|
||||
}
|
||||
const header = new ArrayBuffer(HEADER_SIZE)
|
||||
const headerView = new DataView(header)
|
||||
headerView.setUint32(0, HEADER_SIZE + body.byteLength) // pack_len
|
||||
headerView.setUint16(4, HEADER_SIZE) // raw_header_size
|
||||
headerView.setUint16(6, 1) // ver
|
||||
headerView.setUint32(8, operation) // operation
|
||||
headerView.setUint32(12, 1) // seq_id
|
||||
return new Blob([header, body])
|
||||
}
|
||||
|
||||
sendAuth() {
|
||||
throw Error('Not implemented')
|
||||
}
|
||||
|
||||
async wsConnect() {
|
||||
if (this.isDestroying) {
|
||||
return
|
||||
}
|
||||
|
||||
await this.onBeforeWsConnect()
|
||||
if (this.isDestroying) {
|
||||
return
|
||||
}
|
||||
|
||||
this.websocket = new WebSocket(this.getWsUrl())
|
||||
this.websocket.binaryType = 'arraybuffer'
|
||||
this.websocket.onopen = this.onWsOpen.bind(this)
|
||||
this.websocket.onclose = this.onWsClose.bind(this)
|
||||
this.websocket.onmessage = this.onWsMessage.bind(this)
|
||||
}
|
||||
|
||||
async onBeforeWsConnect() {
|
||||
if (!this.needInitRoom) {
|
||||
return
|
||||
}
|
||||
|
||||
let res
|
||||
try {
|
||||
res = await this.initRoom()
|
||||
} catch (e) {
|
||||
res = false
|
||||
console.error('initRoom exception:', e)
|
||||
if (this.onFatalError) {
|
||||
this.onFatalError(e)
|
||||
}
|
||||
}
|
||||
|
||||
if (!res) {
|
||||
this.onWsClose()
|
||||
throw Error('initRoom failed')
|
||||
}
|
||||
this.needInitRoom = false
|
||||
}
|
||||
|
||||
getWsUrl() {
|
||||
throw Error('Not implemented')
|
||||
}
|
||||
|
||||
onWsOpen() {
|
||||
this.sendAuth()
|
||||
this.heartbeatTimerId = setInterval(this.sendHeartbeat.bind(this), HEARTBEAT_INTERVAL)
|
||||
this.refreshReceiveTimeoutTimer()
|
||||
//console.log('ws 已连接')
|
||||
}
|
||||
|
||||
sendHeartbeat() {
|
||||
this.websocket.send(this.makePacket({}, OP_HEARTBEAT))
|
||||
}
|
||||
|
||||
refreshReceiveTimeoutTimer() {
|
||||
if (this.receiveTimeoutTimerId) {
|
||||
clearTimeout(this.receiveTimeoutTimerId)
|
||||
}
|
||||
this.receiveTimeoutTimerId = setTimeout(this.onReceiveTimeout.bind(this), RECEIVE_TIMEOUT)
|
||||
}
|
||||
|
||||
onReceiveTimeout() {
|
||||
console.warn('接收消息超时')
|
||||
this.discardWebsocket()
|
||||
}
|
||||
|
||||
discardWebsocket() {
|
||||
if (this.receiveTimeoutTimerId) {
|
||||
clearTimeout(this.receiveTimeoutTimerId)
|
||||
this.receiveTimeoutTimerId = null
|
||||
}
|
||||
|
||||
// 直接丢弃阻塞的websocket,不等onclose回调了
|
||||
this.websocket.onopen = this.websocket.onclose = this.websocket.onmessage = null
|
||||
this.websocket.close()
|
||||
this.onWsClose()
|
||||
}
|
||||
|
||||
onWsClose() {
|
||||
this.websocket = null
|
||||
if (this.heartbeatTimerId) {
|
||||
clearInterval(this.heartbeatTimerId)
|
||||
this.heartbeatTimerId = null
|
||||
}
|
||||
if (this.receiveTimeoutTimerId) {
|
||||
clearTimeout(this.receiveTimeoutTimerId)
|
||||
this.receiveTimeoutTimerId = null
|
||||
}
|
||||
|
||||
if (this.isDestroying) {
|
||||
return
|
||||
}
|
||||
this.retryCount++
|
||||
console.warn('心跳超时, 重连中', this.retryCount)
|
||||
setTimeout(this.wsConnect.bind(this), 1000)
|
||||
}
|
||||
|
||||
onWsMessage(event) {
|
||||
if (!(event.data instanceof ArrayBuffer)) {
|
||||
console.warn('未知的websocket消息类型,data=', event.data)
|
||||
return
|
||||
}
|
||||
|
||||
const data = new Uint8Array(event.data)
|
||||
this.parseWsMessage(data)
|
||||
|
||||
// 至少成功处理1条消息
|
||||
this.retryCount = 0
|
||||
}
|
||||
|
||||
parseWsMessage(data) {
|
||||
let offset = 0
|
||||
let dataView = new DataView(data.buffer)
|
||||
let packLen = dataView.getUint32(0)
|
||||
let rawHeaderSize = dataView.getUint16(4)
|
||||
// let ver = dataView.getUint16(6)
|
||||
const operation = dataView.getUint32(8)
|
||||
// let seqId = dataView.getUint32(12)
|
||||
|
||||
switch (operation) {
|
||||
case OP_AUTH_REPLY:
|
||||
case OP_SEND_MSG_REPLY: {
|
||||
// 业务消息,可能有多个包一起发,需要分包
|
||||
while (true) {
|
||||
// eslint-disable-line no-constant-condition
|
||||
const body = new Uint8Array(data.buffer, offset + rawHeaderSize, packLen - rawHeaderSize)
|
||||
this.parseBusinessMessage(dataView, body)
|
||||
|
||||
offset += packLen
|
||||
if (offset >= data.byteLength) {
|
||||
break
|
||||
}
|
||||
|
||||
dataView = new DataView(data.buffer, offset)
|
||||
packLen = dataView.getUint32(0)
|
||||
rawHeaderSize = dataView.getUint16(4)
|
||||
}
|
||||
break
|
||||
}
|
||||
case OP_HEARTBEAT_REPLY: {
|
||||
// 服务器心跳包,包含人气值,这里没用
|
||||
this.refreshReceiveTimeoutTimer()
|
||||
break
|
||||
}
|
||||
default: {
|
||||
// 未知消息
|
||||
const body = new Uint8Array(data.buffer, offset + rawHeaderSize, packLen - rawHeaderSize)
|
||||
console.warn('未知包类型,operation=', operation, dataView, body)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parseBusinessMessage(dataView, body) {
|
||||
const ver = dataView.getUint16(6)
|
||||
const operation = dataView.getUint32(8)
|
||||
|
||||
switch (operation) {
|
||||
case OP_SEND_MSG_REPLY: {
|
||||
// 业务消息
|
||||
if (ver == WS_BODY_PROTOCOL_VERSION_BROTLI) {
|
||||
// 压缩过的先解压
|
||||
body = BrotliDecode(body)
|
||||
this.parseWsMessage(body)
|
||||
} /*else if (ver == WS_BODY_PROTOCOL_VERSION_DEFLATE) {
|
||||
// web端已经不用zlib压缩了,但是开放平台会用
|
||||
body = inflate(body)
|
||||
this.parseWsMessage(body)
|
||||
}*/ else {
|
||||
// 没压缩过的直接反序列化
|
||||
if (body.length !== 0) {
|
||||
try {
|
||||
const text = textDecoder.decode(body)
|
||||
this.onRawMessage(text)
|
||||
this.CMD_CALLBACK_MAP['RAW_MESSAGE']?.call(this, text)
|
||||
body = JSON.parse(text)
|
||||
this.handlerCommand(body)
|
||||
} catch (e) {
|
||||
console.error('body=', body)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
case OP_AUTH_REPLY: {
|
||||
// 认证响应
|
||||
body = JSON.parse(textDecoder.decode(body))
|
||||
if (body.code !== AUTH_REPLY_CODE_OK) {
|
||||
console.error('认证响应错误,body=', body)
|
||||
this.needInitRoom = true
|
||||
this.discardWebsocket()
|
||||
throw new Error('认证响应错误')
|
||||
}
|
||||
this.sendHeartbeat()
|
||||
break
|
||||
}
|
||||
default: {
|
||||
// 未知消息
|
||||
console.warn('未知包类型,operation=', operation, dataView, body)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
onRawMessage(command) {}
|
||||
|
||||
handlerCommand(command) {
|
||||
let cmd = command.cmd || ''
|
||||
const pos = cmd.indexOf(':')
|
||||
if (pos != -1) {
|
||||
cmd = cmd.substr(0, pos)
|
||||
}
|
||||
const callback = this.CMD_CALLBACK_MAP[cmd]
|
||||
if (callback) {
|
||||
callback.call(this, command)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user