-
-
Save jstsmthrgk/2c82124c9ac2bd453658f52c90b8dd44 to your computer and use it in GitHub Desktop.
Workadventure new Federation Patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/front/src/Connexion/ConnectionManager.ts b/front/src/Connexion/ConnectionManager.ts | |
index 026cc20a..67ab3a5b 100644 | |
--- a/front/src/Connexion/ConnectionManager.ts | |
+++ b/front/src/Connexion/ConnectionManager.ts | |
@@ -262,7 +262,8 @@ class ConnectionManager { | |
characterLayers: string[], | |
position: PositionInterface, | |
viewport: ViewportInterface, | |
- companion: string | null | |
+ companion: string | null, | |
+ pusherUrl: string | null | |
): Promise<OnConnectInterface> { | |
return new Promise<OnConnectInterface>((resolve, reject) => { | |
const connection = new RoomConnection( | |
@@ -272,7 +273,8 @@ class ConnectionManager { | |
characterLayers, | |
position, | |
viewport, | |
- companion | |
+ companion, | |
+ pusherUrl | |
); | |
connection.onConnectError((error: object) => { | |
@@ -301,7 +303,7 @@ class ConnectionManager { | |
this.reconnectingTimeout = setTimeout(() => { | |
//todo: allow a way to break recursion? | |
//todo: find a way to avoid recursive function. Otherwise, the call stack will grow indefinitely. | |
- this.connectToRoomSocket(roomUrl, name, characterLayers, position, viewport, companion).then( | |
+ this.connectToRoomSocket(roomUrl, name, characterLayers, position, viewport, companion, pusherUrl).then( | |
(connection) => resolve(connection) | |
); | |
}, 4000 + Math.floor(Math.random() * 2000)); | |
diff --git a/front/src/Connexion/RoomConnection.ts b/front/src/Connexion/RoomConnection.ts | |
index afd08c37..d647c77f 100644 | |
--- a/front/src/Connexion/RoomConnection.ts | |
+++ b/front/src/Connexion/RoomConnection.ts | |
@@ -93,6 +93,7 @@ export class RoomConnection implements RoomConnection { | |
* @param position | |
* @param viewport | |
* @param companion | |
+ * @param pusherUrl | |
*/ | |
public constructor( | |
token: string | null, | |
@@ -101,16 +102,17 @@ export class RoomConnection implements RoomConnection { | |
characterLayers: string[], | |
position: PositionInterface, | |
viewport: ViewportInterface, | |
- companion: string | null | |
+ companion: string | null, | |
+ pusherUrl: string | null | |
) { | |
- let url = new URL(PUSHER_URL, window.location.toString()).toString(); | |
+ let url = new URL(pusherUrl ? pusherUrl : PUSHER_URL, window.location.toString()).toString(); | |
url = url.replace("http://", "ws://").replace("https://", "wss://"); | |
if (!url.endsWith("/")) { | |
url += "/"; | |
} | |
url += "room"; | |
url += "?roomId=" + encodeURIComponent(roomUrl); | |
- url += "&token=" + (token ? encodeURIComponent(token) : ""); | |
+ // url += "&token=" + (token ? encodeURIComponent(token) : ""); | |
url += "&name=" + encodeURIComponent(name); | |
for (const layer of characterLayers) { | |
url += "&characterLayers=" + encodeURIComponent(layer); | |
diff --git a/front/src/Phaser/Game/GameMapProperties.ts b/front/src/Phaser/Game/GameMapProperties.ts | |
index 65ce6ab8..9eaa70f8 100644 | |
--- a/front/src/Phaser/Game/GameMapProperties.ts | |
+++ b/front/src/Phaser/Game/GameMapProperties.ts | |
@@ -26,6 +26,7 @@ export enum GameMapProperties { | |
OPEN_WEBSITE_TRIGGER_MESSAGE = "openWebsiteTriggerMessage", | |
PLAY_AUDIO = "playAudio", | |
PLAY_AUDIO_LOOP = "playAudioLoop", | |
+ PUSHER_URL = "apiUrl", | |
READABLE_BY = "readableBy", | |
SCRIPT = "script", | |
SILENT = "silent", | |
diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts | |
index 30dc8350..2762b7cc 100644 | |
--- a/front/src/Phaser/Game/GameScene.ts | |
+++ b/front/src/Phaser/Game/GameScene.ts | |
@@ -200,6 +200,7 @@ export class GameScene extends DirtyScene { | |
}; | |
private gameMap!: GameMap; | |
+ private pusherUrl: string | null = null; | |
private actionableItems: Map<number, ActionableItem> = new Map<number, ActionableItem>(); | |
// The item that can be selected by pressing the space key. | |
private outlinedItem: ActionableItem | null = null; | |
@@ -692,6 +693,8 @@ export class GameScene extends DirtyScene { | |
* Initializes the connection to Pusher. | |
*/ | |
private connect(): void { | |
+ this.pusherUrl = this.getPusherUrl(this.mapFile); | |
+ | |
const camera = this.cameraManager.getCamera(); | |
connectionManager | |
@@ -708,7 +711,8 @@ export class GameScene extends DirtyScene { | |
right: camera.scrollX + camera.width, | |
bottom: camera.scrollY + camera.height, | |
}, | |
- this.companion | |
+ this.companion, | |
+ this.pusherUrl | |
) | |
.then((onConnect: OnConnectInterface) => { | |
this.connection = onConnect.connection; | |
@@ -1532,6 +1536,10 @@ ${escapedMessage} | |
); | |
} | |
+ private getPusherUrl(map: ITiledMap): string { | |
+ return (this.getProperties(map, GameMapProperties.PUSHER_URL) as string[])[0]; | |
+ } | |
+ | |
private getProperty(layer: ITiledMapLayer | ITiledMap, name: string): string | boolean | number | undefined { | |
const properties: ITiledMapProperty[] | undefined = layer.properties; | |
if (!properties) { | |
diff --git a/pusher/src/Controller/IoSocketController.ts b/pusher/src/Controller/IoSocketController.ts | |
index 9d1f3887..a5ccad33 100644 | |
--- a/pusher/src/Controller/IoSocketController.ts | |
+++ b/pusher/src/Controller/IoSocketController.ts | |
@@ -193,7 +193,9 @@ export class IoSocketController { | |
const websocketExtensions = req.getHeader("sec-websocket-extensions"); | |
const IPAddress = req.getHeader("x-forwarded-for"); | |
- const roomId = query.roomId; | |
+ const roomId = typeof query.roomId != "string" ? | |
+ query.roomId : | |
+ "https://dummy.fediventure.net/_/global" + query.roomId.replace(/[^_]*_\/[^\/]*\//,"/"); | |
try { | |
if (typeof roomId !== "string") { | |
throw new Error("Undefined room ID: "); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment