Skip to content

Commit

Permalink
Cocos Creator: avoid setting .withCredentials on Native platform
Browse files Browse the repository at this point in the history
  • Loading branch information
endel committed Jun 10, 2024
1 parent fd467fb commit 1f1736b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
11 changes: 9 additions & 2 deletions src/HTTP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 #<XMLHttpRequest> which has only a getter"
//
} else {
// always include credentials
options.withCredentials = true;
}

return options;
}
Expand Down
3 changes: 3 additions & 0 deletions typings/cocos-creator.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 1f1736b

Please sign in to comment.