123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- export default class NetworkWebSocket {
- // // ws://192.168.1.208:3000/pve/room
- // url: string = "ws://192.168.1.180:3000/boss/room?uuid=10086&deskId=1"
- // // url: string = "ws://192.168.1.208:3000/boss/room?uuid="
- // ws: { [key: string]: WebSocket } = {}
- // tag: number = 0 // 协议tag
- // cbList: { [tag: string]: Function } = {}
- // log: boolean = false
- // enterRoom(uuid: string) {
- // let key = "boss"
- // if (this.ws[key] && this.ws[key].readyState === WebSocket.OPEN) {
- // return
- // }
- // this.url = `ws://192.168.1.200:3000/boss/room?uuid=${uuid}&deskId=1`
- // if (this.log) {
- // console.warn("C->S WS:", this.url)
- // }
- // this.ws[key] = new WebSocket(this.url)
- // this.ws[key].onopen = (evt) => {
- // console.log("Connection open...")
- // }
- // this.ws[key].onclose = (evt) => {
- // console.log("Connection close...")
- // }
- // this.ws[key].onmessage = (evt) => {
- // if (this.log) {
- // console.warn("S->C WS:", evt.data)
- // }
- // if (evt.data == null) {
- // return
- // }
- // let result: SevBack = JSON.parse(evt.data)
- // if (result == null) {
- // console.error("回调数据异常:", evt.data)
- // return
- // }
- // if (result.ws == null) {
- // return
- // }
- // this.onWsRoom(result, key)
- // }
- // this.ws[key].onerror = (evt) => {
- // console.log("Connection error...", evt)
- // }
- // }
- // preTag: string = ""
- // send(key: string, params: CS_WS, cb?: (data: SevBack) => void) {
- // if (this.preTag.length == 0) {
- // this.preTag = FormulaCom.uuid(4, 2)
- // }
- // if (this.ws[key] == null) {
- // console.error("暂未加入房间", key)
- // return
- // }
- // if (this.ws[key].readyState != WebSocket.OPEN) {
- // console.error("房间连接异常:", key, this.ws[key].readyState)
- // console.error("状态枚举-关闭:", WebSocket.CLOSED)
- // console.error("状态枚举-关闭中", WebSocket.CLOSING)
- // console.error("状态枚举-连接中", WebSocket.CONNECTING)
- // return
- // }
- // this.tag++
- // if (this.tag > 127) {
- // this.tag = 1
- // }
- // if (cb) {
- // this.cbList[this.tag] = cb
- // }
- // params = {
- // tag: this.preTag + "_" + this.tag.toString(),
- // ...params,
- // }
- // if (this.log) {
- // console.warn("C->S WS:", JSON.stringify(params))
- // }
- // this.ws[key].send(JSON.stringify(params))
- // }
- // onWsRoom(result: SevBack, key: string) {
- // // if (result.ws == null) {
- // // return
- // // }
- // // console.log("接受数据:", result)
- // // 刷新后端数据列表
- // let sevback = SevDataMng.sevBackUpdate(GameDataCenter.sevBack, result)
- // // 这里去检测通用类数据的前后对比
- // GameDataCenter.sevBack = sevback
- // // 业务逻辑自定义参数处理
- // GameDataCenter._tModel.forEach(element => {
- // element.doSevback(result)
- // })
- // // 业务逻辑事件触发
- // GameDataCenter._tModel.forEach(element => {
- // element.doEvent(result)
- // })
- // // 执行协议回调
- // if (result.ws.tag && this.cbList[result.ws.tag]) {
- // this.cbList[result.ws.tag](result)
- // delete this.cbList[result.ws.tag]
- // }
- // // if (temp.team) {
- // // GameDataCenter.sevTeam = temp.team
- // // EventMng.emit(SevBackEvent.UP_SEV_TEAM)
- // // }
- // // if (params.ws.pve) {
- // // for (const uuid in params.ws.pve.list) {
- // // cc.game.emit(ServerBridgeEvent.ServerBridgeEvent, uuid, params.ws.pve.list[uuid])
- // // }
- // // }
- // }
- // closeConnect(key: string) {
- // if (this.ws[key]) {
- // this.ws[key].close()
- // delete this.ws[key]
- // }
- // }
- }
|