554979837 发布的帖子
发布在 资源交流 阅读更多

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;
}
发布在 资源交流 阅读更多

![替代文字](![0_1712557518187_XXXX.png](正在上传 100%) 图片地址)