CocosCreator 发布安卓正式包wss连接失败,ws连接正常

CocosCreator 发布安卓正式包wss连接失败,ws连接正常

Android包下WSS连接失败问题

这是一个CocosCreator下发布Andorid原生包的一个坑吧,在creator脚本中,创建websokect的时候,绑定一个网络证书类似 ***.pem文件,

    if (this.wbSocket === null || this.wbSocket.readyState !== this.wbSocket.OPEN) {
        if (cc.sys.isNative) {
            let pemUrl = cc.url.raw('resources/ssl/cacert.pem');
            Utils.log("原生平台-绑定websoket",pemUrl);
            this.wbSocket = new WebSocket(this.wbUrl,null, pemUrl);
        } else {
            this.wbSocket = new WebSocket(this.wbUrl);
        }
        this.wbSocket.binaryType = 'arraybuffer';
        this.wbSocket.onopen = this.onSocketOpen.bind(this);
        this.wbSocket.onmessage = this.onSocketMessage.bind(this);
        this.wbSocket.onerror = this.onSocketError.bind(this);
        this.wbSocket.onclose = this.onSocketClosed.bind(this);
    }else {
        this.reconnect()
    }

pemUrl绑定到webSocket的时候会在vsCode中报错(creator中没有),但是并不影响它的作用

你可能感兴趣的:(cocos-creator,websocket)