Adding an "alone" mode
In "alone" mode (or single-player mode), WorkAdventure does not connect to the server at all. In order to enter the "alone" mode, you need to add "?alone=true" to the URL. "alone" mode can be useful for tutorials (First Time User Experience) where you want to explain how WorkAdventure works without being disturbed by other users.
This commit is contained in:
parent
ad4f8e892e
commit
559e15ebb6
4 changed files with 54 additions and 28 deletions
|
@ -6,24 +6,25 @@ export class Room {
|
|||
public readonly isPublic: boolean;
|
||||
private mapUrl: string|undefined;
|
||||
private instance: string|undefined;
|
||||
private _search: URLSearchParams;
|
||||
|
||||
constructor(id: string) {
|
||||
if (id.startsWith('/')) {
|
||||
id = id.substr(1);
|
||||
const url = new URL(id, 'https://example.com');
|
||||
|
||||
this.id = url.pathname;
|
||||
|
||||
if (this.id.startsWith('/')) {
|
||||
this.id = this.id.substr(1);
|
||||
}
|
||||
this.id = id;
|
||||
if (id.startsWith('_/')) {
|
||||
if (this.id.startsWith('_/')) {
|
||||
this.isPublic = true;
|
||||
} else if (id.startsWith('@/')) {
|
||||
} else if (this.id.startsWith('@/')) {
|
||||
this.isPublic = false;
|
||||
} else {
|
||||
throw new Error('Invalid room ID');
|
||||
}
|
||||
|
||||
const indexOfHash = this.id.indexOf('#');
|
||||
if (indexOfHash !== -1) {
|
||||
this.id = this.id.substr(0, indexOfHash);
|
||||
}
|
||||
this._search = new URLSearchParams(url.search);
|
||||
}
|
||||
|
||||
public static getIdFromIdentifier(identifier: string, baseUrl: string, currentInstance: string): {roomId: string, hash: string} {
|
||||
|
@ -117,4 +118,17 @@ export class Room {
|
|||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
public isDisconnected(): boolean
|
||||
{
|
||||
const alone = this._search.get('alone');
|
||||
if (alone && alone !== '0' && alone.toLowerCase() !== 'false') {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public get search(): URLSearchParams {
|
||||
return this._search;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue