From 1f1736bc6301811d9bc713ddcf6be6b7b1de8534 Mon Sep 17 00:00:00 2001 From: Endel Dreyer Date: Mon, 10 Jun 2024 10:05:38 -0300 Subject: [PATCH] Cocos Creator: avoid setting .withCredentials on Native platform --- package.json | 2 +- src/HTTP.ts | 11 +++++++++-- typings/cocos-creator.d.ts | 3 +++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 9b505d5..99da191 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "colyseus.js", - "version": "0.15.22", + "version": "0.15.23", "description": "Colyseus Multiplayer SDK for JavaScript/TypeScript", "author": "Endel Dreyer", "license": "MIT", diff --git a/src/HTTP.ts b/src/HTTP.ts index daa75a7..5861b3f 100644 --- a/src/HTTP.ts +++ b/src/HTTP.ts @@ -45,8 +45,15 @@ export class HTTP { options.headers['Authorization'] = `Bearer ${this.authToken}`; } - // always include credentials - options.withCredentials = true; + if (typeof (cc) !== 'undefined' && cc.sys && cc.sys.isNative) { + // + // Workaround for Cocos Creator on Native platform + // "Cannot set property withCredentials of # which has only a getter" + // + } else { + // always include credentials + options.withCredentials = true; + } return options; } diff --git a/typings/cocos-creator.d.ts b/typings/cocos-creator.d.ts index 7082fb3..d811a3f 100644 --- a/typings/cocos-creator.d.ts +++ b/typings/cocos-creator.d.ts @@ -9,5 +9,8 @@ declare module cc { export interface Isys { /** cc.sys.localStorage is a local storage component. */ localStorage: Storage; + + /** Is native ? This is set to be true in jsb auto. */ + isNative: boolean; } }