(function(win) { const rawHeaderLen = 18; const packetOffset = 0; const headerOffset = 4; const verOffset = 6; const opOffset = 8; const seqOffset = 12; const compressOffset = 16; const ctypeOffset = 17; var Client = function(options) { var MAX_CONNECT_TIMES = 10; var DELAY = 15000; this.options = options || {}; this.createConnect(MAX_CONNECT_TIMES, DELAY); } Client.prototype.createConnect = function(max, delay) { var self = this; if (max === 0) { return; } connect(); var textDecoder = new TextDecoder(); var textEncoder = new TextEncoder(); var heartbeatInterval; function connect() { var ws = new WebSocket('ws://172.22.33.126:7822/sub'); ws.binaryType = 'arraybuffer'; ws.onopen = function() { console.log("auth start") auth(); register(); } ws.onmessage = function(evt) { var data = evt.data; var dataView = new DataView(data, 0); var packetLen = dataView.getInt32(packetOffset); var headerLen = dataView.getInt16(headerOffset); var ver = dataView.getInt16(verOffset); var op = dataView.getInt32(opOffset); var seq = dataView.getInt32(seqOffset); var msgBody = textDecoder.decode(data.slice(headerLen, packetLen)); console.log("receiveHeader: packetLen=" + packetLen, "headerLen=" + headerLen, "ver=" + ver, "op=" + op, "seq=" + seq,"body="+msgBody); switch(op) { case 8: // heartbeat heartbeat(); heartbeatInterval = setInterval(heartbeat, 30 * 1000); break; case 3: // heartbeat reply console.log("receive: heartbeat online=", dataView.getInt32(rawHeaderLen)); break; case 5: // batch message for (var offset=0; offset