Merge branch 'develop' of github.com:thecodingmachine/workadventure into main
This commit is contained in:
commit
b6693b9ea7
@ -45,88 +45,90 @@ const roomManager: IRoomManagerServer = {
|
|||||||
let room: GameRoom | null = null;
|
let room: GameRoom | null = null;
|
||||||
let user: User | null = null;
|
let user: User | null = null;
|
||||||
|
|
||||||
call.on("data", async (message: PusherToBackMessage) => {
|
call.on("data", (message: PusherToBackMessage) => {
|
||||||
try {
|
(async () => {
|
||||||
if (room === null || user === null) {
|
try {
|
||||||
if (message.hasJoinroommessage()) {
|
if (room === null || user === null) {
|
||||||
socketManager
|
if (message.hasJoinroommessage()) {
|
||||||
.handleJoinRoom(call, message.getJoinroommessage() as JoinRoomMessage)
|
socketManager
|
||||||
.then(({ room: gameRoom, user: myUser }) => {
|
.handleJoinRoom(call, message.getJoinroommessage() as JoinRoomMessage)
|
||||||
if (call.writable) {
|
.then(({ room: gameRoom, user: myUser }) => {
|
||||||
room = gameRoom;
|
if (call.writable) {
|
||||||
user = myUser;
|
room = gameRoom;
|
||||||
} else {
|
user = myUser;
|
||||||
//Connexion may have been closed before the init was finished, so we have to manually disconnect the user.
|
} else {
|
||||||
socketManager.leaveRoom(gameRoom, myUser);
|
//Connexion may have been closed before the init was finished, so we have to manually disconnect the user.
|
||||||
}
|
socketManager.leaveRoom(gameRoom, myUser);
|
||||||
})
|
}
|
||||||
.catch((e) => emitError(call, e));
|
})
|
||||||
} else {
|
.catch((e) => emitError(call, e));
|
||||||
throw new Error("The first message sent MUST be of type JoinRoomMessage");
|
} else {
|
||||||
}
|
throw new Error("The first message sent MUST be of type JoinRoomMessage");
|
||||||
} else {
|
|
||||||
if (message.hasJoinroommessage()) {
|
|
||||||
throw new Error("Cannot call JoinRoomMessage twice!");
|
|
||||||
} else if (message.hasUsermovesmessage()) {
|
|
||||||
socketManager.handleUserMovesMessage(
|
|
||||||
room,
|
|
||||||
user,
|
|
||||||
message.getUsermovesmessage() as UserMovesMessage
|
|
||||||
);
|
|
||||||
} else if (message.hasSilentmessage()) {
|
|
||||||
socketManager.handleSilentMessage(room, user, message.getSilentmessage() as SilentMessage);
|
|
||||||
} else if (message.hasItemeventmessage()) {
|
|
||||||
socketManager.handleItemEvent(room, user, message.getItemeventmessage() as ItemEventMessage);
|
|
||||||
} else if (message.hasVariablemessage()) {
|
|
||||||
await socketManager.handleVariableEvent(
|
|
||||||
room,
|
|
||||||
user,
|
|
||||||
message.getVariablemessage() as VariableMessage
|
|
||||||
);
|
|
||||||
} else if (message.hasWebrtcsignaltoservermessage()) {
|
|
||||||
socketManager.emitVideo(
|
|
||||||
room,
|
|
||||||
user,
|
|
||||||
message.getWebrtcsignaltoservermessage() as WebRtcSignalToServerMessage
|
|
||||||
);
|
|
||||||
} else if (message.hasWebrtcscreensharingsignaltoservermessage()) {
|
|
||||||
socketManager.emitScreenSharing(
|
|
||||||
room,
|
|
||||||
user,
|
|
||||||
message.getWebrtcscreensharingsignaltoservermessage() as WebRtcSignalToServerMessage
|
|
||||||
);
|
|
||||||
} else if (message.hasPlayglobalmessage()) {
|
|
||||||
socketManager.emitPlayGlobalMessage(room, message.getPlayglobalmessage() as PlayGlobalMessage);
|
|
||||||
} else if (message.hasQueryjitsijwtmessage()) {
|
|
||||||
socketManager.handleQueryJitsiJwtMessage(
|
|
||||||
user,
|
|
||||||
message.getQueryjitsijwtmessage() as QueryJitsiJwtMessage
|
|
||||||
);
|
|
||||||
} else if (message.hasEmotepromptmessage()) {
|
|
||||||
socketManager.handleEmoteEventMessage(
|
|
||||||
room,
|
|
||||||
user,
|
|
||||||
message.getEmotepromptmessage() as EmotePromptMessage
|
|
||||||
);
|
|
||||||
} else if (message.hasSendusermessage()) {
|
|
||||||
const sendUserMessage = message.getSendusermessage();
|
|
||||||
if (sendUserMessage !== undefined) {
|
|
||||||
socketManager.handlerSendUserMessage(user, sendUserMessage);
|
|
||||||
}
|
|
||||||
} else if (message.hasBanusermessage()) {
|
|
||||||
const banUserMessage = message.getBanusermessage();
|
|
||||||
if (banUserMessage !== undefined) {
|
|
||||||
socketManager.handlerBanUserMessage(room, user, banUserMessage);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Unhandled message type");
|
if (message.hasJoinroommessage()) {
|
||||||
|
throw new Error("Cannot call JoinRoomMessage twice!");
|
||||||
|
} else if (message.hasUsermovesmessage()) {
|
||||||
|
socketManager.handleUserMovesMessage(
|
||||||
|
room,
|
||||||
|
user,
|
||||||
|
message.getUsermovesmessage() as UserMovesMessage
|
||||||
|
);
|
||||||
|
} else if (message.hasSilentmessage()) {
|
||||||
|
socketManager.handleSilentMessage(room, user, message.getSilentmessage() as SilentMessage);
|
||||||
|
} else if (message.hasItemeventmessage()) {
|
||||||
|
socketManager.handleItemEvent(room, user, message.getItemeventmessage() as ItemEventMessage);
|
||||||
|
} else if (message.hasVariablemessage()) {
|
||||||
|
await socketManager.handleVariableEvent(
|
||||||
|
room,
|
||||||
|
user,
|
||||||
|
message.getVariablemessage() as VariableMessage
|
||||||
|
);
|
||||||
|
} else if (message.hasWebrtcsignaltoservermessage()) {
|
||||||
|
socketManager.emitVideo(
|
||||||
|
room,
|
||||||
|
user,
|
||||||
|
message.getWebrtcsignaltoservermessage() as WebRtcSignalToServerMessage
|
||||||
|
);
|
||||||
|
} else if (message.hasWebrtcscreensharingsignaltoservermessage()) {
|
||||||
|
socketManager.emitScreenSharing(
|
||||||
|
room,
|
||||||
|
user,
|
||||||
|
message.getWebrtcscreensharingsignaltoservermessage() as WebRtcSignalToServerMessage
|
||||||
|
);
|
||||||
|
} else if (message.hasPlayglobalmessage()) {
|
||||||
|
socketManager.emitPlayGlobalMessage(room, message.getPlayglobalmessage() as PlayGlobalMessage);
|
||||||
|
} else if (message.hasQueryjitsijwtmessage()) {
|
||||||
|
socketManager.handleQueryJitsiJwtMessage(
|
||||||
|
user,
|
||||||
|
message.getQueryjitsijwtmessage() as QueryJitsiJwtMessage
|
||||||
|
);
|
||||||
|
} else if (message.hasEmotepromptmessage()) {
|
||||||
|
socketManager.handleEmoteEventMessage(
|
||||||
|
room,
|
||||||
|
user,
|
||||||
|
message.getEmotepromptmessage() as EmotePromptMessage
|
||||||
|
);
|
||||||
|
} else if (message.hasSendusermessage()) {
|
||||||
|
const sendUserMessage = message.getSendusermessage();
|
||||||
|
if (sendUserMessage !== undefined) {
|
||||||
|
socketManager.handlerSendUserMessage(user, sendUserMessage);
|
||||||
|
}
|
||||||
|
} else if (message.hasBanusermessage()) {
|
||||||
|
const banUserMessage = message.getBanusermessage();
|
||||||
|
if (banUserMessage !== undefined) {
|
||||||
|
socketManager.handlerBanUserMessage(room, user, banUserMessage);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Error("Unhandled message type");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
emitError(call, e);
|
||||||
|
call.end();
|
||||||
}
|
}
|
||||||
} catch (e) {
|
})().catch(e => console.error(e));
|
||||||
console.error(e);
|
|
||||||
emitError(call, e);
|
|
||||||
call.end();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
call.on("end", () => {
|
call.on("end", () => {
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import {Observable, Subject} from "rxjs";
|
import { Observable, Subject } from "rxjs";
|
||||||
|
|
||||||
import { EnterLeaveEvent, isEnterLeaveEvent } from "../Events/EnterLeaveEvent";
|
import { EnterLeaveEvent, isEnterLeaveEvent } from "../Events/EnterLeaveEvent";
|
||||||
|
|
||||||
import {IframeApiContribution, queryWorkadventure, sendToWorkadventure} from "./IframeApiContribution";
|
import { IframeApiContribution, queryWorkadventure, sendToWorkadventure } from "./IframeApiContribution";
|
||||||
import { apiCallback } from "./registeredCallbacks";
|
import { apiCallback } from "./registeredCallbacks";
|
||||||
import {isSetVariableEvent, SetVariableEvent} from "../Events/SetVariableEvent";
|
import { isSetVariableEvent, SetVariableEvent } from "../Events/SetVariableEvent";
|
||||||
|
|
||||||
import type { ITiledMap } from "../../Phaser/Map/ITiledMap";
|
import type { ITiledMap } from "../../Phaser/Map/ITiledMap";
|
||||||
|
|
||||||
@ -19,8 +19,7 @@ export const initVariables = (_variables: Map<string, unknown>): void => {
|
|||||||
variables.set(name, value);
|
variables.set(name, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
}
|
|
||||||
|
|
||||||
setVariableResolvers.subscribe((event) => {
|
setVariableResolvers.subscribe((event) => {
|
||||||
const oldValue = variables.get(event.key);
|
const oldValue = variables.get(event.key);
|
||||||
@ -44,19 +43,19 @@ export class WorkadventureStateCommands extends IframeApiContribution<Workadvent
|
|||||||
typeChecker: isSetVariableEvent,
|
typeChecker: isSetVariableEvent,
|
||||||
callback: (payloadData) => {
|
callback: (payloadData) => {
|
||||||
setVariableResolvers.next(payloadData);
|
setVariableResolvers.next(payloadData);
|
||||||
}
|
},
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
|
||||||
saveVariable(key : string, value : unknown): Promise<void> {
|
saveVariable(key: string, value: unknown): Promise<void> {
|
||||||
variables.set(key, value);
|
variables.set(key, value);
|
||||||
return queryWorkadventure({
|
return queryWorkadventure({
|
||||||
type: 'setVariable',
|
type: "setVariable",
|
||||||
data: {
|
data: {
|
||||||
key,
|
key,
|
||||||
value
|
value,
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
loadVariable(key: string): unknown {
|
loadVariable(key: string): unknown {
|
||||||
@ -71,7 +70,6 @@ export class WorkadventureStateCommands extends IframeApiContribution<Workadvent
|
|||||||
}
|
}
|
||||||
return subject.asObservable();
|
return subject.asObservable();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const proxyCommand = new Proxy(new WorkadventureStateCommands(), {
|
const proxyCommand = new Proxy(new WorkadventureStateCommands(), {
|
||||||
@ -86,7 +84,7 @@ const proxyCommand = new Proxy(new WorkadventureStateCommands(), {
|
|||||||
// User must use WA.state.saveVariable to have error message.
|
// User must use WA.state.saveVariable to have error message.
|
||||||
target.saveVariable(p.toString(), value);
|
target.saveVariable(p.toString(), value);
|
||||||
return true;
|
return true;
|
||||||
}
|
},
|
||||||
});
|
}) as WorkadventureStateCommands & { [key: string]: unknown };
|
||||||
|
|
||||||
export default proxyCommand;
|
export default proxyCommand;
|
||||||
|
Loading…
Reference in New Issue
Block a user