Merge branch 'develop' into feature/player-companion

This commit is contained in:
Johannes Berthel 2021-04-02 23:40:30 +02:00
commit 4aa082d83b
25 changed files with 421 additions and 166 deletions

View file

@ -1,5 +1,5 @@
import Axios from "axios";
import {API_URL, START_ROOM_URL} from "../Enum/EnvironmentVariable";
import {PUSHER_URL, START_ROOM_URL} from "../Enum/EnvironmentVariable";
import {RoomConnection} from "./RoomConnection";
import {OnConnectInterface, PositionInterface, ViewportInterface} from "./ConnexionModels";
import {GameConnexionTypes, urlManager} from "../Url/UrlManager";
@ -34,7 +34,7 @@ class ConnectionManager {
this.connexionType = connexionType;
if(connexionType === GameConnexionTypes.register) {
const organizationMemberToken = urlManager.getOrganizationToken();
const data = await Axios.post(`${API_URL}/register`, {organizationMemberToken}).then(res => res.data);
const data = await Axios.post(`${PUSHER_URL}/register`, {organizationMemberToken}).then(res => res.data);
this.localUser = new LocalUser(data.userUuid, data.authToken, data.textures);
localUserStore.saveUser(this.localUser);
@ -69,15 +69,15 @@ class ConnectionManager {
return Promise.resolve(new Room(roomId));
}
return Promise.reject('Invalid URL');
return Promise.reject(new Error('Invalid URL'));
}
private async verifyToken(token: string): Promise<void> {
await Axios.get(`${API_URL}/verify`, {params: {token}});
await Axios.get(`${PUSHER_URL}/verify`, {params: {token}});
}
public async anonymousLogin(isBenchmark: boolean = false): Promise<void> {
const data = await Axios.post(`${API_URL}/anonymLogin`).then(res => res.data);
const data = await Axios.post(`${PUSHER_URL}/anonymLogin`).then(res => res.data);
this.localUser = new LocalUser(data.userUuid, data.authToken, []);
if (!isBenchmark) { // In benchmark, we don't have a local storage.
localUserStore.saveUser(this.localUser);

View file

@ -1,5 +1,5 @@
import Axios from "axios";
import {API_URL} from "../Enum/EnvironmentVariable";
import {PUSHER_URL} from "../Enum/EnvironmentVariable";
export class Room {
public readonly id: string;
@ -67,7 +67,7 @@ export class Room {
// We have a private ID, we need to query the map URL from the server.
const urlParts = this.parsePrivateUrl(this.id);
Axios.get(`${API_URL}/map`, {
Axios.get(`${PUSHER_URL}/map`, {
params: urlParts
}).then(({data}) => {
console.log('Map ', this.id, ' resolves to URL ', data.mapUrl);

View file

@ -1,4 +1,4 @@
import {API_URL, UPLOADER_URL} from "../Enum/EnvironmentVariable";
import {PUSHER_URL, UPLOADER_URL} from "../Enum/EnvironmentVariable";
import Axios from "axios";
import {
BatchMessage,
@ -67,8 +67,12 @@ export class RoomConnection implements RoomConnection {
* @param roomId The ID of the room in the form "_/[instance]/[map_url]" or "@/[org]/[event]/[map]"
*/
public constructor(token: string|null, roomId: string, name: string, characterLayers: string[], position: PositionInterface, viewport: ViewportInterface, companion: string|null) {
let url = API_URL.replace('http://', 'ws://').replace('https://', 'wss://');
url += '/room';
let url = new URL(PUSHER_URL, window.location.toString()).toString();
url = url.replace('http://', 'ws://').replace('https://', 'wss://');
if (!url.endsWith('/')) {
url += '/';
}
url += 'room';
url += '?roomId='+(roomId ?encodeURIComponent(roomId):'');
url += '&token='+(token ?encodeURIComponent(token):'');
url += '&name='+encodeURIComponent(name);
@ -187,6 +191,8 @@ export class RoomConnection implements RoomConnection {
adminMessagesService.onSendusermessage(message.getSendusermessage() as BanUserMessage);
} else if (message.hasWorldfullwarningmessage()) {
worldFullWarningStream.onMessage();
} else if (message.hasRefreshroommessage()) {
//todo: implement a way to notify the user the room was refreshed.
} else {
throw new Error('Unknown message received');
}
@ -388,7 +394,7 @@ export class RoomConnection implements RoomConnection {
public onConnectError(callback: (error: Event) => void): void {
this.socket.addEventListener('error', callback)
}
public onConnect(callback: (roomConnection: OnConnectInterface) => void): void {
//this.socket.addEventListener('open', callback)
this.onMessage(EventMessage.CONNECT, callback);