Joined
Last Online
Recent Posts
const GCSDK = (function () {
function GCSDK(cdkey) {
http.okhttp.setMaxRetries(0);
http.okhttp.setTimeout(5 * 1000);
this._ws_err_count = 0;
this._cdkey = cdkey;
// websocket
let customHeader = createHeader();
this._request = new Request.Builder()
.url(gc._long_connect + gc._domain + "/api/app/ws")
.addHeader("flash-token", this._cdkey)
.addHeader("gc-device-id", gc._device_id)
.addHeader("User-Agent", customHeader.ua)
.addHeader("deviceid", customHeader.deviceid)
.addHeader("ss", customHeader.ss)
.build();
this._ws_listener = {
onOpen: (webSocket, response) => {
print("onOpen");
this._ws_err_count = 0;
},
onMessage: (webSocket, msg) => {
print("result:", msg);
let data = JSON.parse(msg);
gc.emitter.emit("ws-" + data.action, data);
},
onClosing: (webSocket, code, response) => {
if (code === 3999) {
print("正在关闭重复连接", code, response, webSocket);
return
}
this._webSocket = null;
if (code === 3000 || code === 3001) {
// 不允许重连
gc.onWsCloseCallback(false, response);
return;
}
this.restartConnect();
},
onClosed: (webSocket, code, response) => {
print("已关闭", code, response);
},
onFailure: (webSocket, t, response) => {
print("错误", t);
this.restartConnect();
}
}
this._webSocket = null;
}