Allow loading https maps from http protocol
In a development environment, we often run in HTTP. The problem is that WorkAdventure will attempt to load maps using the HTTP protocol (even if the map is on a remote server that is available only in HTTPS). This commit adds a "fallback". If we are in HTTP (so in a development environment) and if the map fails to load correctly, we will try again, but in HTTPS. This allows development environment to load maps hosted on a HTTPS enabled server easily.
This commit is contained in:
parent
4b8a2aca34
commit
b6edefbe4e
@ -190,6 +190,15 @@ export class GameScene extends ResizableScene implements CenterListener {
|
|||||||
|
|
||||||
this.load.image(openChatIconName, 'resources/objects/talk.png');
|
this.load.image(openChatIconName, 'resources/objects/talk.png');
|
||||||
this.load.on(FILE_LOAD_ERROR, (file: {src: string}) => {
|
this.load.on(FILE_LOAD_ERROR, (file: {src: string}) => {
|
||||||
|
// If we happen to be in HTTP and we are trying to load a URL in HTTPS only... (this happens only in dev environments)
|
||||||
|
if (window.location.protocol === 'http:' && file.src === this.MapUrlFile && file.src.startsWith('http:')) {
|
||||||
|
this.MapUrlFile = this.MapUrlFile.replace('http://', 'https://');
|
||||||
|
this.load.tilemapTiledJSON(this.MapUrlFile, this.MapUrlFile);
|
||||||
|
this.load.on('filecomplete-tilemapJSON-'+this.MapUrlFile, (key: string, type: string, data: unknown) => {
|
||||||
|
this.onMapLoad(data);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.scene.start(ErrorSceneName, {
|
this.scene.start(ErrorSceneName, {
|
||||||
title: 'Network error',
|
title: 'Network error',
|
||||||
subTitle: 'An error occurred while loading resource:',
|
subTitle: 'An error occurred while loading resource:',
|
||||||
@ -306,7 +315,7 @@ export class GameScene extends ResizableScene implements CenterListener {
|
|||||||
gameManager.gameSceneIsCreated(this);
|
gameManager.gameSceneIsCreated(this);
|
||||||
urlManager.pushRoomIdToUrl(this.room);
|
urlManager.pushRoomIdToUrl(this.room);
|
||||||
this.startLayerName = urlManager.getStartLayerNameFromUrl();
|
this.startLayerName = urlManager.getStartLayerNameFromUrl();
|
||||||
|
|
||||||
this.messageSubscription = worldFullMessageStream.stream.subscribe((message) => this.showWorldFullError())
|
this.messageSubscription = worldFullMessageStream.stream.subscribe((message) => this.showWorldFullError())
|
||||||
|
|
||||||
const playerName = gameManager.getPlayerName();
|
const playerName = gameManager.getPlayerName();
|
||||||
@ -582,7 +591,7 @@ export class GameScene extends ResizableScene implements CenterListener {
|
|||||||
contextRed.stroke();
|
contextRed.stroke();
|
||||||
this.circleRedTexture.refresh();
|
this.circleRedTexture.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private safeParseJSONstring(jsonString: string|undefined, propertyName: string) {
|
private safeParseJSONstring(jsonString: string|undefined, propertyName: string) {
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user