2021-05-10 21:48:11 +02:00
|
|
|
import { PUSHER_URL, UPLOADER_URL } from "../Enum/EnvironmentVariable";
|
2020-10-01 14:11:34 +02:00
|
|
|
import Axios from "axios";
|
2020-05-15 22:40:06 +02:00
|
|
|
|
2021-05-18 15:18:35 +02:00
|
|
|
import type { UserSimplePeerInterface } from "../WebRtc/SimplePeer";
|
2021-05-10 21:48:11 +02:00
|
|
|
import { ProtobufClientUtils } from "../Network/ProtobufClientUtils";
|
2022-01-03 15:23:28 +01:00
|
|
|
import type {
|
2021-06-25 18:14:40 +02:00
|
|
|
GroupCreatedUpdatedMessageInterface,
|
|
|
|
ItemEventMessageInterface,
|
|
|
|
MessageUserJoined,
|
|
|
|
OnConnectInterface,
|
2021-12-22 18:30:23 +01:00
|
|
|
PlayerDetailsUpdatedMessageInterface,
|
2021-06-25 18:14:40 +02:00
|
|
|
PlayGlobalMessageInterface,
|
|
|
|
PositionInterface,
|
2020-09-25 18:29:22 +02:00
|
|
|
RoomJoinedMessageInterface,
|
2021-06-25 18:14:40 +02:00
|
|
|
ViewportInterface,
|
|
|
|
WebRtcDisconnectMessageInterface,
|
2020-09-25 18:29:22 +02:00
|
|
|
WebRtcSignalReceivedMessageInterface,
|
|
|
|
} from "./ConnexionModels";
|
2021-05-18 15:18:35 +02:00
|
|
|
import type { BodyResourceDescriptionInterface } from "../Phaser/Entity/PlayerTextures";
|
2021-05-10 21:48:11 +02:00
|
|
|
import { adminMessagesService } from "./AdminMessagesService";
|
|
|
|
import { connectionManager } from "./ConnectionManager";
|
2021-12-12 16:56:26 +01:00
|
|
|
import { get } from "svelte/store";
|
2021-07-29 18:02:36 +02:00
|
|
|
import { warningContainerStore } from "../Stores/MenuStore";
|
2021-12-24 15:49:25 +01:00
|
|
|
import { followStateStore, followRoleStore, followUsersStore } from "../Stores/FollowStore";
|
2021-12-15 19:47:14 +01:00
|
|
|
import { localUserStore } from "./LocalUserStore";
|
2022-01-03 15:23:28 +01:00
|
|
|
import {
|
|
|
|
RefreshRoomMessage,
|
|
|
|
ServerToClientMessage as ServerToClientMessageTsProto,
|
|
|
|
TokenExpiredMessage,
|
|
|
|
WorldConnexionMessage,
|
|
|
|
WorldFullMessage,
|
|
|
|
ErrorMessage as ErrorMessageTsProto,
|
|
|
|
UserMovedMessage as UserMovedMessageTsProto,
|
|
|
|
GroupUpdateMessage as GroupUpdateMessageTsProto,
|
|
|
|
GroupDeleteMessage as GroupDeleteMessageTsProto,
|
|
|
|
UserJoinedMessage as UserJoinedMessageTsProto,
|
|
|
|
UserLeftMessage as UserLeftMessageTsProto,
|
|
|
|
ItemEventMessage as ItemEventMessageTsProto,
|
|
|
|
EmoteEventMessage as EmoteEventMessageTsProto,
|
|
|
|
VariableMessage as VariableMessageTsProto,
|
|
|
|
PlayerDetailsUpdatedMessage as PlayerDetailsUpdatedMessageTsProto,
|
|
|
|
WorldFullWarningMessage,
|
|
|
|
WebRtcDisconnectMessage as WebRtcDisconnectMessageTsProto,
|
|
|
|
PlayGlobalMessage as PlayGlobalMessageTsProto,
|
|
|
|
StopGlobalMessage as StopGlobalMessageTsProto,
|
|
|
|
SendJitsiJwtMessage as SendJitsiJwtMessageTsProto,
|
|
|
|
SendUserMessage as SendUserMessageTsProto,
|
|
|
|
BanUserMessage as BanUserMessageTsProto,
|
|
|
|
ClientToServerMessage as ClientToServerMessageTsProto,
|
|
|
|
PositionMessage as PositionMessageTsProto,
|
|
|
|
ViewportMessage as ViewportMessageTsProto,
|
|
|
|
PositionMessage_Direction,
|
|
|
|
SetPlayerDetailsMessage as SetPlayerDetailsMessageTsProto,
|
|
|
|
PingMessage as PingMessageTsProto,
|
|
|
|
} from "../Messages/ts-proto-generated/messages";
|
|
|
|
import { Subject } from "rxjs";
|
|
|
|
import { OpenPopupEvent } from "../Api/Events/OpenPopupEvent";
|
|
|
|
import { match } from "assert";
|
2020-09-25 18:29:22 +02:00
|
|
|
|
2020-11-10 18:26:46 +01:00
|
|
|
const manualPingDelay = 20000;
|
|
|
|
|
2020-09-25 18:29:22 +02:00
|
|
|
export class RoomConnection implements RoomConnection {
|
2020-09-28 18:52:54 +02:00
|
|
|
private readonly socket: WebSocket;
|
2021-05-10 21:48:11 +02:00
|
|
|
private userId: number | null = null;
|
2020-09-29 16:01:22 +02:00
|
|
|
private listeners: Map<string, Function[]> = new Map<string, Function[]>();
|
2021-05-10 21:48:11 +02:00
|
|
|
private static websocketFactory: null | ((url: string) => any) = null; // eslint-disable-line @typescript-eslint/no-explicit-any
|
2020-10-01 17:16:49 +02:00
|
|
|
private closed: boolean = false;
|
2020-10-14 11:07:34 +02:00
|
|
|
private tags: string[] = [];
|
2021-12-01 16:38:34 +01:00
|
|
|
private _userRoomToken: string | undefined;
|
2020-04-07 20:41:35 +02:00
|
|
|
|
2022-01-03 15:23:28 +01:00
|
|
|
private readonly _errorMessageStream = new Subject<ErrorMessageTsProto>();
|
|
|
|
public readonly errorMessageStream = this._errorMessageStream.asObservable();
|
|
|
|
|
|
|
|
private readonly _roomJoinedMessageStream = new Subject<{
|
|
|
|
connection: RoomConnection;
|
|
|
|
room: RoomJoinedMessageInterface;
|
|
|
|
}>();
|
|
|
|
public readonly roomJoinedMessageStream = this._roomJoinedMessageStream.asObservable();
|
|
|
|
|
|
|
|
private readonly _webRtcStartMessageStream = new Subject<UserSimplePeerInterface>();
|
|
|
|
public readonly webRtcStartMessageStream = this._webRtcStartMessageStream.asObservable();
|
|
|
|
|
|
|
|
private readonly _webRtcSignalToClientMessageStream = new Subject<WebRtcSignalReceivedMessageInterface>();
|
|
|
|
public readonly webRtcSignalToClientMessageStream = this._webRtcSignalToClientMessageStream.asObservable();
|
|
|
|
|
|
|
|
private readonly _webRtcScreenSharingSignalToClientMessageStream =
|
|
|
|
new Subject<WebRtcSignalReceivedMessageInterface>();
|
|
|
|
public readonly webRtcScreenSharingSignalToClientMessageStream =
|
|
|
|
this._webRtcScreenSharingSignalToClientMessageStream.asObservable();
|
|
|
|
|
|
|
|
private readonly _webRtcDisconnectMessageStream = new Subject<WebRtcDisconnectMessageTsProto>();
|
|
|
|
public readonly webRtcDisconnectMessageStream = this._webRtcDisconnectMessageStream.asObservable();
|
|
|
|
|
|
|
|
private readonly _teleportMessageMessageStream = new Subject<string>();
|
|
|
|
public readonly teleportMessageMessageStream = this._teleportMessageMessageStream.asObservable();
|
|
|
|
|
|
|
|
private readonly _sendJitsiJwtMessageStream = new Subject<SendJitsiJwtMessageTsProto>();
|
|
|
|
public readonly sendJitsiJwtMessageStream = this._sendJitsiJwtMessageStream.asObservable();
|
|
|
|
|
|
|
|
private readonly _worldFullMessageStream = new Subject<string | null>();
|
|
|
|
public readonly worldFullMessageStream = this._worldFullMessageStream.asObservable();
|
|
|
|
|
|
|
|
private readonly _worldConnexionMessageStream = new Subject<WorldConnexionMessage>();
|
|
|
|
public readonly worldConnexionMessageStream = this._worldConnexionMessageStream.asObservable();
|
|
|
|
|
|
|
|
private readonly _tokenExpiredMessageStream = new Subject<TokenExpiredMessage>();
|
|
|
|
public readonly tokenExpiredMessageStream = this._tokenExpiredMessageStream.asObservable();
|
|
|
|
|
|
|
|
private readonly _userMovedMessageStream = new Subject<UserMovedMessageTsProto>();
|
|
|
|
public readonly userMovedMessageStream = this._userMovedMessageStream.asObservable();
|
|
|
|
|
|
|
|
private readonly _groupUpdateMessageStream = new Subject<GroupCreatedUpdatedMessageInterface>();
|
|
|
|
public readonly groupUpdateMessageStream = this._groupUpdateMessageStream.asObservable();
|
|
|
|
|
|
|
|
private readonly _groupDeleteMessageStream = new Subject<GroupDeleteMessageTsProto>();
|
|
|
|
public readonly groupDeleteMessageStream = this._groupDeleteMessageStream.asObservable();
|
|
|
|
|
|
|
|
private readonly _userJoinedMessageStream = new Subject<MessageUserJoined>();
|
|
|
|
public readonly userJoinedMessageStream = this._userJoinedMessageStream.asObservable();
|
|
|
|
|
|
|
|
private readonly _userLeftMessageStream = new Subject<UserLeftMessageTsProto>();
|
|
|
|
public readonly userLeftMessageStream = this._userLeftMessageStream.asObservable();
|
|
|
|
|
|
|
|
private readonly _itemEventMessageStream = new Subject<{
|
|
|
|
itemId: number;
|
|
|
|
event: string;
|
|
|
|
parameters: unknown;
|
|
|
|
state: unknown;
|
|
|
|
}>();
|
|
|
|
public readonly itemEventMessageStream = this._itemEventMessageStream.asObservable();
|
|
|
|
|
|
|
|
private readonly _emoteEventMessageStream = new Subject<EmoteEventMessageTsProto>();
|
|
|
|
public readonly emoteEventMessageStream = this._emoteEventMessageStream.asObservable();
|
|
|
|
|
|
|
|
private readonly _variableMessageStream = new Subject<{ name: string; value: unknown }>();
|
|
|
|
public readonly variableMessageStream = this._variableMessageStream.asObservable();
|
|
|
|
|
|
|
|
private readonly _playerDetailsUpdatedMessageStream = new Subject<PlayerDetailsUpdatedMessageTsProto>();
|
|
|
|
public readonly playerDetailsUpdatedMessageStream = this._playerDetailsUpdatedMessageStream.asObservable();
|
|
|
|
|
|
|
|
private readonly _connectionErrorStream = new Subject<CloseEvent>();
|
|
|
|
public readonly connectionErrorStream = this._connectionErrorStream.asObservable();
|
|
|
|
|
2021-06-25 18:45:15 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2021-06-25 18:14:40 +02:00
|
|
|
public static setWebsocketFactory(websocketFactory: (url: string) => any): void {
|
2020-09-29 17:12:28 +02:00
|
|
|
RoomConnection.websocketFactory = websocketFactory;
|
2020-09-28 18:52:54 +02:00
|
|
|
}
|
2020-06-22 15:00:23 +02:00
|
|
|
|
2020-10-06 18:09:23 +02:00
|
|
|
/**
|
|
|
|
*
|
2021-07-27 16:37:01 +02:00
|
|
|
* @param token A JWT token containing the email of the user
|
2021-07-13 19:09:07 +02:00
|
|
|
* @param roomUrl The URL of the room in the form "https://example.com/_/[instance]/[map_url]" or "https://example.com/@/[org]/[event]/[map]"
|
2021-09-05 18:17:49 +02:00
|
|
|
* @param name
|
|
|
|
* @param characterLayers
|
|
|
|
* @param position
|
|
|
|
* @param viewport
|
|
|
|
* @param companion
|
2020-10-06 18:09:23 +02:00
|
|
|
*/
|
2021-06-25 18:14:40 +02:00
|
|
|
public constructor(
|
|
|
|
token: string | null,
|
2021-07-13 19:09:07 +02:00
|
|
|
roomUrl: string,
|
2021-06-25 18:14:40 +02:00
|
|
|
name: string,
|
|
|
|
characterLayers: string[],
|
|
|
|
position: PositionInterface,
|
|
|
|
viewport: ViewportInterface,
|
|
|
|
companion: string | null
|
|
|
|
) {
|
2021-03-31 16:38:51 +02:00
|
|
|
let url = new URL(PUSHER_URL, window.location.toString()).toString();
|
2021-06-25 18:14:40 +02:00
|
|
|
url = url.replace("http://", "ws://").replace("https://", "wss://");
|
|
|
|
if (!url.endsWith("/")) {
|
|
|
|
url += "/";
|
2021-03-31 17:50:27 +02:00
|
|
|
}
|
2021-06-25 18:14:40 +02:00
|
|
|
url += "room";
|
2021-07-15 17:12:54 +02:00
|
|
|
url += "?roomId=" + encodeURIComponent(roomUrl);
|
2021-06-25 18:14:40 +02:00
|
|
|
url += "&token=" + (token ? encodeURIComponent(token) : "");
|
|
|
|
url += "&name=" + encodeURIComponent(name);
|
2020-10-09 17:14:03 +02:00
|
|
|
for (const layer of characterLayers) {
|
2021-06-25 18:14:40 +02:00
|
|
|
url += "&characterLayers=" + encodeURIComponent(layer);
|
2020-10-06 18:09:23 +02:00
|
|
|
}
|
2021-06-25 18:14:40 +02:00
|
|
|
url += "&x=" + Math.floor(position.x);
|
|
|
|
url += "&y=" + Math.floor(position.y);
|
|
|
|
url += "&top=" + Math.floor(viewport.top);
|
|
|
|
url += "&bottom=" + Math.floor(viewport.bottom);
|
|
|
|
url += "&left=" + Math.floor(viewport.left);
|
|
|
|
url += "&right=" + Math.floor(viewport.right);
|
|
|
|
if (typeof companion === "string") {
|
|
|
|
url += "&companion=" + encodeURIComponent(companion);
|
2021-04-02 21:21:11 +02:00
|
|
|
}
|
2020-09-15 10:06:11 +02:00
|
|
|
|
2020-09-29 17:12:28 +02:00
|
|
|
if (RoomConnection.websocketFactory) {
|
|
|
|
this.socket = RoomConnection.websocketFactory(url);
|
2020-09-28 18:52:54 +02:00
|
|
|
} else {
|
|
|
|
this.socket = new WebSocket(url);
|
|
|
|
}
|
2020-09-18 15:51:15 +02:00
|
|
|
|
2021-06-25 18:14:40 +02:00
|
|
|
this.socket.binaryType = "arraybuffer";
|
2020-09-28 18:52:54 +02:00
|
|
|
|
2021-05-10 21:48:11 +02:00
|
|
|
let interval: ReturnType<typeof setInterval> | undefined = undefined;
|
2020-12-03 16:39:44 +01:00
|
|
|
|
2020-09-28 18:52:54 +02:00
|
|
|
this.socket.onopen = (ev) => {
|
2020-11-10 18:26:46 +01:00
|
|
|
//we manually ping every 20s to not be logged out by the server, even when the game is in background.
|
2022-01-03 15:23:28 +01:00
|
|
|
const pingMessage = PingMessageTsProto.encode({}).finish();
|
|
|
|
interval = setInterval(() => this.socket.send(pingMessage), manualPingDelay);
|
2020-09-28 18:52:54 +02:00
|
|
|
};
|
|
|
|
|
2021-06-25 18:14:40 +02:00
|
|
|
this.socket.addEventListener("close", (event) => {
|
2020-12-03 16:39:44 +01:00
|
|
|
if (interval) {
|
|
|
|
clearInterval(interval);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we are not connected yet (if a JoinRoomMessage was not sent), we need to retry.
|
2021-03-05 18:25:27 +01:00
|
|
|
if (this.userId === null && !this.closed) {
|
2022-01-03 15:23:28 +01:00
|
|
|
this._connectionErrorStream.next(event);
|
2020-12-03 16:39:44 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-09-28 18:52:54 +02:00
|
|
|
this.socket.onmessage = (messageEvent) => {
|
|
|
|
const arrayBuffer: ArrayBuffer = messageEvent.data;
|
|
|
|
|
2022-01-03 15:23:28 +01:00
|
|
|
const serverToClientMessage = ServerToClientMessageTsProto.decode(new Uint8Array(arrayBuffer));
|
|
|
|
//const message = ServerToClientMessage.deserializeBinary(new Uint8Array(arrayBuffer));
|
|
|
|
|
|
|
|
const message = serverToClientMessage.message;
|
|
|
|
if (message === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (message.$case) {
|
|
|
|
case "batchMessage": {
|
|
|
|
for (const subMessageWrapper of message.batchMessage.payload) {
|
|
|
|
const subMessage = subMessageWrapper.message;
|
|
|
|
if (subMessage === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (subMessage.$case) {
|
|
|
|
case "errorMessage": {
|
|
|
|
this._errorMessageStream.next(subMessage.errorMessage);
|
|
|
|
console.error("An error occurred server side: " + subMessage.errorMessage.message);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "userJoinedMessage": {
|
|
|
|
this._userJoinedMessageStream.next(
|
|
|
|
this.toMessageUserJoined(subMessage.userJoinedMessage)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "userLeftMessage": {
|
|
|
|
this._userLeftMessageStream.next(subMessage.userLeftMessage);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "userMovedMessage": {
|
|
|
|
this._userMovedMessageStream.next(subMessage.userMovedMessage);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "groupUpdateMessage": {
|
|
|
|
this._groupUpdateMessageStream.next(
|
|
|
|
this.toGroupCreatedUpdatedMessage(subMessage.groupUpdateMessage)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "groupDeleteMessage": {
|
|
|
|
this._groupDeleteMessageStream.next(subMessage.groupDeleteMessage);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "itemEventMessage": {
|
|
|
|
this._itemEventMessageStream.next({
|
|
|
|
itemId: subMessage.itemEventMessage.itemId,
|
|
|
|
event: subMessage.itemEventMessage.event,
|
|
|
|
parameters: JSON.parse(subMessage.itemEventMessage.parametersJson),
|
|
|
|
state: JSON.parse(subMessage.itemEventMessage.stateJson),
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "emoteEventMessage": {
|
|
|
|
this._emoteEventMessageStream.next(subMessage.emoteEventMessage);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "playerDetailsUpdatedMessage": {
|
|
|
|
this._playerDetailsUpdatedMessageStream.next(subMessage.playerDetailsUpdatedMessage);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "variableMessage": {
|
|
|
|
const name = subMessage.variableMessage.name;
|
|
|
|
const serializedValue = subMessage.variableMessage.value;
|
|
|
|
let value: unknown = undefined;
|
|
|
|
if (serializedValue) {
|
|
|
|
try {
|
|
|
|
value = JSON.parse(serializedValue);
|
|
|
|
} catch (e) {
|
|
|
|
console.error(
|
|
|
|
'Unable to unserialize value received from server for variable "' +
|
|
|
|
name +
|
|
|
|
'". Value received: "' +
|
|
|
|
serializedValue +
|
|
|
|
'". Error: ',
|
|
|
|
e
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this._variableMessageStream.next({ name, value });
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
// Security check: if we forget a "case", the line below will catch the error at compile-time.
|
|
|
|
const tmp: never = subMessage;
|
|
|
|
}
|
|
|
|
}
|
2021-03-31 11:21:06 +02:00
|
|
|
}
|
2022-01-03 15:23:28 +01:00
|
|
|
break;
|
2020-09-18 15:51:15 +02:00
|
|
|
}
|
2022-01-03 15:23:28 +01:00
|
|
|
case "roomJoinedMessage": {
|
|
|
|
const roomJoinedMessage = message.roomJoinedMessage;
|
2020-09-28 18:52:54 +02:00
|
|
|
|
2022-01-03 15:23:28 +01:00
|
|
|
const items: { [itemId: number]: unknown } = {};
|
|
|
|
for (const item of roomJoinedMessage.item) {
|
|
|
|
items[item.itemId] = JSON.parse(item.stateJson);
|
|
|
|
}
|
2020-09-28 18:52:54 +02:00
|
|
|
|
2022-01-03 15:23:28 +01:00
|
|
|
const variables = new Map<string, unknown>();
|
|
|
|
for (const variable of roomJoinedMessage.variable) {
|
|
|
|
try {
|
|
|
|
variables.set(variable.name, JSON.parse(variable.value));
|
|
|
|
} catch (e) {
|
|
|
|
console.error(
|
|
|
|
'Unable to unserialize value received from server for variable "' +
|
|
|
|
variable.name +
|
|
|
|
'". Value received: "' +
|
|
|
|
variable.value +
|
|
|
|
'". Error: ',
|
|
|
|
e
|
|
|
|
);
|
|
|
|
}
|
2021-07-19 18:46:33 +02:00
|
|
|
}
|
2021-07-07 17:17:28 +02:00
|
|
|
|
2022-01-03 15:23:28 +01:00
|
|
|
this.userId = roomJoinedMessage.currentUserId;
|
|
|
|
this.tags = roomJoinedMessage.tag;
|
|
|
|
this._userRoomToken = roomJoinedMessage.userRoomToken;
|
|
|
|
|
|
|
|
this._roomJoinedMessageStream.next({
|
|
|
|
connection: this,
|
|
|
|
room: {
|
|
|
|
items,
|
|
|
|
variables,
|
|
|
|
} as RoomJoinedMessageInterface,
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "worldFullMessage": {
|
|
|
|
this._worldFullMessageStream.next(null);
|
|
|
|
this.closed = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "tokenExpiredMessage": {
|
|
|
|
connectionManager.logout();
|
|
|
|
this.closed = true; //technically, this isn't needed since loadOpenIDScreen() will do window.location.assign() but I prefer to leave it for consistency
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "worldConnexionMessage": {
|
|
|
|
this._worldFullMessageStream.next(message.worldConnexionMessage.message);
|
|
|
|
this.closed = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "webRtcSignalToClientMessage": {
|
|
|
|
this._webRtcSignalToClientMessageStream.next({
|
|
|
|
userId: message.webRtcSignalToClientMessage.userId,
|
|
|
|
signal: JSON.parse(message.webRtcSignalToClientMessage.signal),
|
|
|
|
webRtcUser: message.webRtcSignalToClientMessage.webrtcUserName
|
|
|
|
? message.webRtcSignalToClientMessage.webrtcUserName
|
|
|
|
: undefined,
|
|
|
|
webRtcPassword: message.webRtcSignalToClientMessage.webrtcPassword
|
|
|
|
? message.webRtcSignalToClientMessage.webrtcPassword
|
|
|
|
: undefined,
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "webRtcScreenSharingSignalToClientMessage": {
|
|
|
|
this._webRtcScreenSharingSignalToClientMessageStream.next({
|
|
|
|
userId: message.webRtcScreenSharingSignalToClientMessage.userId,
|
|
|
|
signal: JSON.parse(message.webRtcScreenSharingSignalToClientMessage.signal),
|
|
|
|
webRtcUser: message.webRtcScreenSharingSignalToClientMessage.webrtcUserName
|
|
|
|
? message.webRtcScreenSharingSignalToClientMessage.webrtcUserName
|
|
|
|
: undefined,
|
|
|
|
webRtcPassword: message.webRtcScreenSharingSignalToClientMessage.webrtcPassword
|
|
|
|
? message.webRtcScreenSharingSignalToClientMessage.webrtcPassword
|
|
|
|
: undefined,
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "webRtcStartMessage": {
|
|
|
|
this._webRtcStartMessageStream.next({
|
|
|
|
userId: message.webRtcStartMessage.userId,
|
|
|
|
initiator: message.webRtcStartMessage.initiator,
|
|
|
|
webRtcUser: message.webRtcStartMessage.webrtcUserName
|
|
|
|
? message.webRtcStartMessage.webrtcUserName
|
|
|
|
: undefined,
|
|
|
|
webRtcPassword: message.webRtcStartMessage.webrtcPassword
|
|
|
|
? message.webRtcStartMessage.webrtcPassword
|
|
|
|
: undefined,
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "webRtcDisconnectMessage": {
|
|
|
|
this._webRtcDisconnectMessageStream.next(message.webRtcDisconnectMessage);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "teleportMessageMessage": {
|
|
|
|
// FIXME: WHY IS THIS UNUSED? CAN WE REMOVE THIS???
|
|
|
|
this._teleportMessageMessageStream.next(message.teleportMessageMessage.map);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "sendJitsiJwtMessage": {
|
|
|
|
this._sendJitsiJwtMessageStream.next(message.sendJitsiJwtMessage);
|
|
|
|
break;
|
2021-12-15 19:47:14 +01:00
|
|
|
}
|
2022-01-03 15:23:28 +01:00
|
|
|
case "sendUserMessage": {
|
|
|
|
adminMessagesService.onSendusermessage(message.sendUserMessage);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "banUserMessage": {
|
|
|
|
adminMessagesService.onSendusermessage(message.banUserMessage);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "worldFullWarningMessage": {
|
|
|
|
warningContainerStore.activateWarningContainer();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "refreshRoomMessage": {
|
|
|
|
//todo: implement a way to notify the user the room was refreshed.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "followRequestMessage": {
|
|
|
|
if (!localUserStore.getIgnoreFollowRequests()) {
|
|
|
|
followUsersStore.addFollowRequest(message.followRequestMessage.leader);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "followConfirmationMessage": {
|
|
|
|
followUsersStore.addFollower(message.followConfirmationMessage.follower);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "followAbortMessage": {
|
|
|
|
if (get(followRoleStore) === "follower") {
|
|
|
|
followUsersStore.stopFollowing();
|
|
|
|
} else {
|
|
|
|
followUsersStore.removeFollower(message.followAbortMessage.follower);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "errorMessage": {
|
|
|
|
this._errorMessageStream.next(message.errorMessage);
|
|
|
|
console.error("An error occurred server side: " + message.errorMessage.message);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
// Security check: if we forget a "case", the line below will catch the error at compile-time.
|
|
|
|
const tmp: never = message;
|
2021-12-12 16:56:26 +01:00
|
|
|
}
|
2020-09-15 10:06:11 +02:00
|
|
|
}
|
2021-06-25 18:14:40 +02:00
|
|
|
};
|
2020-04-10 12:54:05 +02:00
|
|
|
}
|
|
|
|
|
2020-09-29 16:01:22 +02:00
|
|
|
private dispatch(event: string, payload: unknown): void {
|
|
|
|
const listeners = this.listeners.get(event);
|
|
|
|
if (listeners === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (const listener of listeners) {
|
|
|
|
listener(payload);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-22 18:30:23 +01:00
|
|
|
/*public emitPlayerDetailsMessage(userName: string, characterLayersSelected: BodyResourceDescriptionInterface[]) {
|
2020-09-25 18:29:22 +02:00
|
|
|
const message = new SetPlayerDetailsMessage();
|
2020-09-29 17:24:16 +02:00
|
|
|
message.setName(userName);
|
2020-10-20 16:39:23 +02:00
|
|
|
message.setCharacterlayersList(characterLayersSelected.map((characterLayer) => characterLayer.name));
|
2020-06-22 16:10:18 +02:00
|
|
|
|
2020-09-29 17:12:28 +02:00
|
|
|
const clientToServerMessage = new ClientToServerMessage();
|
|
|
|
clientToServerMessage.setSetplayerdetailsmessage(message);
|
2020-09-28 18:52:54 +02:00
|
|
|
|
2021-12-22 18:30:23 +01:00
|
|
|
this.socket.send(clientToServerMessage.serializeBinary().buffer);
|
|
|
|
}*/
|
|
|
|
|
|
|
|
public emitPlayerOutlineColor(color: number | null) {
|
2022-01-03 15:23:28 +01:00
|
|
|
let message: SetPlayerDetailsMessageTsProto;
|
2021-12-22 18:30:23 +01:00
|
|
|
if (color === null) {
|
2022-01-03 15:23:28 +01:00
|
|
|
message = SetPlayerDetailsMessageTsProto.fromPartial({
|
|
|
|
removeOutlineColor: true,
|
|
|
|
});
|
2021-12-22 18:30:23 +01:00
|
|
|
} else {
|
2022-01-03 15:23:28 +01:00
|
|
|
message = SetPlayerDetailsMessageTsProto.fromPartial({
|
|
|
|
outlineColor: color,
|
|
|
|
});
|
2021-12-22 18:30:23 +01:00
|
|
|
}
|
|
|
|
|
2022-01-03 15:23:28 +01:00
|
|
|
const bytes = ClientToServerMessageTsProto.encode({
|
|
|
|
message: {
|
|
|
|
$case: "setPlayerDetailsMessage",
|
|
|
|
setPlayerDetailsMessage: message,
|
|
|
|
},
|
|
|
|
}).finish();
|
2021-12-22 18:30:23 +01:00
|
|
|
|
2022-01-03 15:23:28 +01:00
|
|
|
this.socket.send(bytes);
|
2020-04-05 20:57:14 +02:00
|
|
|
}
|
2020-05-10 17:31:27 +02:00
|
|
|
|
2020-06-22 11:58:07 +02:00
|
|
|
public closeConnection(): void {
|
|
|
|
this.socket?.close();
|
2020-10-01 17:16:49 +02:00
|
|
|
this.closed = true;
|
2020-06-03 11:55:31 +02:00
|
|
|
}
|
|
|
|
|
2022-01-03 15:23:28 +01:00
|
|
|
private toPositionMessage(x: number, y: number, direction: string, moving: boolean): PositionMessageTsProto {
|
|
|
|
return {
|
|
|
|
x: Math.floor(x),
|
|
|
|
y: Math.floor(y),
|
|
|
|
moving,
|
|
|
|
direction: (() => {
|
|
|
|
switch (direction) {
|
|
|
|
case "up":
|
|
|
|
return PositionMessage_Direction.UP;
|
|
|
|
case "down":
|
|
|
|
return PositionMessage_Direction.DOWN;
|
|
|
|
case "left":
|
|
|
|
return PositionMessage_Direction.LEFT;
|
|
|
|
case "right":
|
|
|
|
return PositionMessage_Direction.RIGHT;
|
|
|
|
default:
|
|
|
|
throw new Error("Unexpected direction");
|
|
|
|
}
|
|
|
|
})(),
|
|
|
|
};
|
2020-09-28 18:52:54 +02:00
|
|
|
}
|
|
|
|
|
2022-01-03 15:23:28 +01:00
|
|
|
private toViewportMessage(viewport: ViewportInterface): ViewportMessageTsProto {
|
|
|
|
return {
|
|
|
|
left: Math.floor(viewport.left),
|
|
|
|
right: Math.floor(viewport.right),
|
|
|
|
top: Math.floor(viewport.top),
|
|
|
|
bottom: Math.floor(viewport.bottom),
|
|
|
|
};
|
2020-09-28 18:52:54 +02:00
|
|
|
}
|
|
|
|
|
2021-05-10 21:48:11 +02:00
|
|
|
public sharePosition(x: number, y: number, direction: string, moving: boolean, viewport: ViewportInterface): void {
|
|
|
|
if (!this.socket) {
|
2020-09-28 18:52:54 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const positionMessage = this.toPositionMessage(x, y, direction, moving);
|
|
|
|
|
|
|
|
const viewportMessage = this.toViewportMessage(viewport);
|
|
|
|
|
2022-01-03 15:23:28 +01:00
|
|
|
const bytes = ClientToServerMessageTsProto.encode({
|
|
|
|
message: {
|
|
|
|
$case: "userMovesMessage",
|
|
|
|
userMovesMessage: {
|
|
|
|
position: positionMessage,
|
|
|
|
viewport: viewportMessage,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}).finish();
|
2020-09-24 10:05:16 +02:00
|
|
|
|
2022-01-03 15:23:28 +01:00
|
|
|
this.socket.send(bytes);
|
2020-04-05 20:57:14 +02:00
|
|
|
}
|
|
|
|
|
2020-08-31 14:03:40 +02:00
|
|
|
public setSilent(silent: boolean): void {
|
2022-01-03 15:23:28 +01:00
|
|
|
const bytes = ClientToServerMessageTsProto.encode({
|
|
|
|
message: {
|
|
|
|
$case: "silentMessage",
|
|
|
|
silentMessage: {
|
|
|
|
silent,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}).finish();
|
2020-09-28 18:52:54 +02:00
|
|
|
|
2022-01-03 15:23:28 +01:00
|
|
|
this.socket.send(bytes);
|
2020-08-31 14:03:40 +02:00
|
|
|
}
|
|
|
|
|
2020-09-15 16:21:41 +02:00
|
|
|
public setViewport(viewport: ViewportInterface): void {
|
2022-01-03 15:23:28 +01:00
|
|
|
const bytes = ClientToServerMessageTsProto.encode({
|
|
|
|
message: {
|
|
|
|
$case: "viewportMessage",
|
|
|
|
viewportMessage: this.toViewportMessage(viewport),
|
|
|
|
},
|
|
|
|
}).finish();
|
2020-09-28 18:52:54 +02:00
|
|
|
|
2022-01-03 15:23:28 +01:00
|
|
|
this.socket.send(bytes);
|
2020-04-05 20:57:14 +02:00
|
|
|
}
|
|
|
|
|
2022-01-03 15:23:28 +01:00
|
|
|
/* public onUserJoins(callback: (message: MessageUserJoined) => void): void {
|
2020-09-29 16:01:22 +02:00
|
|
|
this.onMessage(EventMessage.JOIN_ROOM, (message: UserJoinedMessage) => {
|
2020-09-28 18:52:54 +02:00
|
|
|
callback(this.toMessageUserJoined(message));
|
2020-09-24 14:50:28 +02:00
|
|
|
});
|
2022-01-03 15:23:28 +01:00
|
|
|
}*/
|
2020-05-19 19:11:12 +02:00
|
|
|
|
2020-09-28 18:52:54 +02:00
|
|
|
// TODO: move this to protobuf utils
|
2022-01-03 15:23:28 +01:00
|
|
|
private toMessageUserJoined(message: UserJoinedMessageTsProto): MessageUserJoined {
|
|
|
|
const position = message.position;
|
2020-09-28 18:52:54 +02:00
|
|
|
if (position === undefined) {
|
2021-06-25 18:14:40 +02:00
|
|
|
throw new Error("Invalid JOIN_ROOM message");
|
2020-09-28 18:52:54 +02:00
|
|
|
}
|
2020-10-20 16:39:23 +02:00
|
|
|
|
2022-01-03 15:23:28 +01:00
|
|
|
const characterLayers = message.characterLayers.map((characterLayer): BodyResourceDescriptionInterface => {
|
|
|
|
return {
|
|
|
|
name: characterLayer.name,
|
|
|
|
img: characterLayer.url,
|
|
|
|
};
|
|
|
|
});
|
2020-10-20 16:39:23 +02:00
|
|
|
|
2022-01-03 15:23:28 +01:00
|
|
|
const companion = message.companion;
|
2021-04-02 21:21:11 +02:00
|
|
|
|
2020-09-28 18:52:54 +02:00
|
|
|
return {
|
2022-01-03 15:23:28 +01:00
|
|
|
userId: message.userId,
|
|
|
|
name: message.name,
|
2020-10-20 16:39:23 +02:00
|
|
|
characterLayers,
|
2022-01-03 15:23:28 +01:00
|
|
|
visitCardUrl: message.visitCardUrl,
|
2021-04-02 21:21:11 +02:00
|
|
|
position: ProtobufClientUtils.toPointInterface(position),
|
2022-01-03 15:23:28 +01:00
|
|
|
companion: companion ? companion.name : null,
|
|
|
|
userUuid: message.userUuid,
|
|
|
|
outlineColor: message.hasOutline ? message.outlineColor : undefined,
|
2021-06-25 18:14:40 +02:00
|
|
|
};
|
2020-09-28 18:52:54 +02:00
|
|
|
}
|
|
|
|
|
2020-09-18 15:51:15 +02:00
|
|
|
/**
|
|
|
|
* Registers a listener on a message that is part of a batch
|
|
|
|
*/
|
2020-09-29 16:01:22 +02:00
|
|
|
private onMessage(eventName: string, callback: Function): void {
|
|
|
|
let callbacks = this.listeners.get(eventName);
|
2020-09-18 15:51:15 +02:00
|
|
|
if (callbacks === undefined) {
|
|
|
|
callbacks = new Array<Function>();
|
2020-09-29 16:01:22 +02:00
|
|
|
this.listeners.set(eventName, callbacks);
|
2020-09-18 15:51:15 +02:00
|
|
|
}
|
|
|
|
callbacks.push(callback);
|
2020-05-19 19:11:12 +02:00
|
|
|
}
|
|
|
|
|
2022-01-03 15:23:28 +01:00
|
|
|
private toGroupCreatedUpdatedMessage(message: GroupUpdateMessageTsProto): GroupCreatedUpdatedMessageInterface {
|
|
|
|
const position = message.position;
|
2020-09-28 18:52:54 +02:00
|
|
|
if (position === undefined) {
|
2021-06-25 18:14:40 +02:00
|
|
|
throw new Error("Missing position in GROUP_CREATE_UPDATE");
|
2020-09-28 18:52:54 +02:00
|
|
|
}
|
2020-09-21 11:24:03 +02:00
|
|
|
|
2020-09-28 18:52:54 +02:00
|
|
|
return {
|
2022-01-03 15:23:28 +01:00
|
|
|
groupId: message.groupId,
|
|
|
|
position: position,
|
|
|
|
groupSize: message.groupSize,
|
2021-06-25 18:14:40 +02:00
|
|
|
};
|
2020-05-08 00:35:36 +02:00
|
|
|
}
|
|
|
|
|
2020-09-28 18:52:54 +02:00
|
|
|
public onConnectError(callback: (error: Event) => void): void {
|
2021-06-25 18:14:40 +02:00
|
|
|
this.socket.addEventListener("error", callback);
|
2020-09-28 18:52:54 +02:00
|
|
|
}
|
2021-03-31 16:00:14 +02:00
|
|
|
|
2020-09-18 13:57:38 +02:00
|
|
|
public sendWebrtcSignal(signal: unknown, receiverId: number) {
|
2022-01-03 15:23:28 +01:00
|
|
|
const bytes = ClientToServerMessageTsProto.encode({
|
|
|
|
message: {
|
|
|
|
$case: "webRtcSignalToServerMessage",
|
|
|
|
webRtcSignalToServerMessage: {
|
|
|
|
receiverId,
|
|
|
|
signal: JSON.stringify(signal),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}).finish();
|
2020-09-29 16:01:22 +02:00
|
|
|
|
2022-01-03 15:23:28 +01:00
|
|
|
this.socket.send(bytes);
|
2020-04-25 16:05:33 +02:00
|
|
|
}
|
|
|
|
|
2020-09-18 13:57:38 +02:00
|
|
|
public sendWebrtcScreenSharingSignal(signal: unknown, receiverId: number) {
|
2022-01-03 15:23:28 +01:00
|
|
|
const bytes = ClientToServerMessageTsProto.encode({
|
|
|
|
message: {
|
|
|
|
$case: "webRtcScreenSharingSignalToServerMessage",
|
|
|
|
webRtcScreenSharingSignalToServerMessage: {
|
|
|
|
receiverId,
|
|
|
|
signal: JSON.stringify(signal),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}).finish();
|
2020-04-25 16:05:33 +02:00
|
|
|
|
2022-01-03 15:23:28 +01:00
|
|
|
this.socket.send(bytes);
|
2020-04-25 16:05:33 +02:00
|
|
|
}
|
|
|
|
|
2021-03-26 14:12:22 +01:00
|
|
|
public onServerDisconnected(callback: () => void): void {
|
2021-06-25 18:14:40 +02:00
|
|
|
this.socket.addEventListener("close", (event) => {
|
2021-03-26 14:12:22 +01:00
|
|
|
if (this.closed === true || connectionManager.unloading) {
|
2020-10-01 17:16:49 +02:00
|
|
|
return;
|
|
|
|
}
|
2021-06-25 18:14:40 +02:00
|
|
|
console.log("Socket closed with code " + event.code + ". Reason: " + event.reason);
|
2020-09-28 18:52:54 +02:00
|
|
|
if (event.code === 1000) {
|
|
|
|
// Normal closure case
|
2020-06-22 15:00:23 +02:00
|
|
|
return;
|
|
|
|
}
|
2021-03-26 14:12:22 +01:00
|
|
|
callback();
|
2020-05-13 20:22:42 +02:00
|
|
|
});
|
2020-06-22 18:42:54 +02:00
|
|
|
}
|
2020-06-17 15:37:02 +02:00
|
|
|
|
2021-02-02 18:19:51 +01:00
|
|
|
public getUserId(): number {
|
2021-06-25 18:14:40 +02:00
|
|
|
if (this.userId === null) throw "UserId cannot be null!";
|
2020-06-22 18:42:54 +02:00
|
|
|
return this.userId;
|
2020-05-13 20:22:42 +02:00
|
|
|
}
|
|
|
|
|
2020-09-24 17:24:37 +02:00
|
|
|
emitActionableEvent(itemId: number, event: string, state: unknown, parameters: unknown): void {
|
2022-01-03 15:23:28 +01:00
|
|
|
const bytes = ClientToServerMessageTsProto.encode({
|
|
|
|
message: {
|
|
|
|
$case: "itemEventMessage",
|
|
|
|
itemEventMessage: {
|
|
|
|
itemId,
|
|
|
|
event,
|
|
|
|
stateJson: JSON.stringify(state),
|
|
|
|
parametersJson: JSON.stringify(parameters),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}).finish();
|
2020-09-24 17:24:37 +02:00
|
|
|
|
2022-01-03 15:23:28 +01:00
|
|
|
this.socket.send(bytes);
|
2020-07-27 22:36:07 +02:00
|
|
|
}
|
|
|
|
|
2021-07-06 10:58:12 +02:00
|
|
|
emitSetVariableEvent(name: string, value: unknown): void {
|
2022-01-03 15:23:28 +01:00
|
|
|
const bytes = ClientToServerMessageTsProto.encode({
|
|
|
|
message: {
|
|
|
|
$case: "variableMessage",
|
|
|
|
variableMessage: {
|
|
|
|
name,
|
|
|
|
value: JSON.stringify(value),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}).finish();
|
2021-07-06 10:58:12 +02:00
|
|
|
|
2022-01-03 15:23:28 +01:00
|
|
|
this.socket.send(bytes);
|
2021-12-22 18:30:23 +01:00
|
|
|
}
|
|
|
|
|
2021-05-10 21:48:11 +02:00
|
|
|
public uploadAudio(file: FormData) {
|
2021-06-25 18:14:40 +02:00
|
|
|
return Axios.post(`${UPLOADER_URL}/upload-audio-message`, file)
|
|
|
|
.then((res: { data: {} }) => {
|
|
|
|
return res.data;
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
console.error(err);
|
|
|
|
throw err;
|
|
|
|
});
|
2020-10-01 14:11:34 +02:00
|
|
|
}
|
|
|
|
|
2021-07-22 16:14:27 +02:00
|
|
|
public emitGlobalMessage(message: PlayGlobalMessageInterface): void {
|
2022-01-03 15:23:28 +01:00
|
|
|
const bytes = ClientToServerMessageTsProto.encode({
|
|
|
|
message: {
|
|
|
|
$case: "playGlobalMessage",
|
|
|
|
playGlobalMessage: {
|
|
|
|
type: message.type,
|
|
|
|
content: message.content,
|
|
|
|
broadcastToWorld: message.broadcastToWorld,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}).finish();
|
2020-10-01 14:11:34 +02:00
|
|
|
|
2022-01-03 15:23:28 +01:00
|
|
|
this.socket.send(bytes);
|
2020-10-01 14:11:34 +02:00
|
|
|
}
|
2020-10-12 11:22:41 +02:00
|
|
|
|
2021-07-07 11:24:51 +02:00
|
|
|
public emitReportPlayerMessage(reportedUserUuid: string, reportComment: string): void {
|
2022-01-03 15:23:28 +01:00
|
|
|
const bytes = ClientToServerMessageTsProto.encode({
|
|
|
|
message: {
|
|
|
|
$case: "reportPlayerMessage",
|
|
|
|
reportPlayerMessage: {
|
|
|
|
reportedUserUuid,
|
|
|
|
reportComment,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}).finish();
|
2020-10-12 11:22:41 +02:00
|
|
|
|
2022-01-03 15:23:28 +01:00
|
|
|
this.socket.send(bytes);
|
2020-10-12 11:22:41 +02:00
|
|
|
}
|
2020-10-14 15:06:10 +02:00
|
|
|
|
2021-05-10 21:48:11 +02:00
|
|
|
public emitQueryJitsiJwtMessage(jitsiRoom: string, tag: string | undefined): void {
|
2022-01-03 15:23:28 +01:00
|
|
|
const bytes = ClientToServerMessageTsProto.encode({
|
|
|
|
message: {
|
|
|
|
$case: "queryJitsiJwtMessage",
|
|
|
|
queryJitsiJwtMessage: {
|
|
|
|
jitsiRoom,
|
|
|
|
tag: tag ?? "", // empty string is sent as "undefined" by ts-proto
|
|
|
|
// TODO: when we migrated "pusher" to ts-proto, migrate this to a StringValue
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}).finish();
|
2020-10-16 19:13:26 +02:00
|
|
|
|
2022-01-03 15:23:28 +01:00
|
|
|
this.socket.send(bytes);
|
2021-07-07 17:17:28 +02:00
|
|
|
}
|
|
|
|
|
2020-10-14 11:07:34 +02:00
|
|
|
public hasTag(tag: string): boolean {
|
2020-10-14 11:48:34 +02:00
|
|
|
return this.tags.includes(tag);
|
2020-10-14 11:07:34 +02:00
|
|
|
}
|
2021-02-16 09:58:08 +01:00
|
|
|
|
2020-12-04 11:30:35 +01:00
|
|
|
public isAdmin(): boolean {
|
2021-06-25 18:14:40 +02:00
|
|
|
return this.hasTag("admin");
|
2020-12-04 11:30:35 +01:00
|
|
|
}
|
2021-03-31 11:21:06 +02:00
|
|
|
|
|
|
|
public emitEmoteEvent(emoteName: string): void {
|
2022-01-03 15:23:28 +01:00
|
|
|
const bytes = ClientToServerMessageTsProto.encode({
|
|
|
|
message: {
|
|
|
|
$case: "emotePromptMessage",
|
|
|
|
emotePromptMessage: {
|
|
|
|
emote: emoteName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}).finish();
|
2021-03-31 11:21:06 +02:00
|
|
|
|
2022-01-03 15:23:28 +01:00
|
|
|
this.socket.send(bytes);
|
2021-03-31 11:21:06 +02:00
|
|
|
}
|
2021-05-26 10:58:25 +02:00
|
|
|
|
2021-12-15 14:48:45 +01:00
|
|
|
public emitFollowRequest(): void {
|
|
|
|
if (!this.userId) {
|
2021-12-12 16:56:26 +01:00
|
|
|
return;
|
|
|
|
}
|
2022-01-03 15:23:28 +01:00
|
|
|
|
|
|
|
const bytes = ClientToServerMessageTsProto.encode({
|
|
|
|
message: {
|
|
|
|
$case: "followRequestMessage",
|
|
|
|
followRequestMessage: {
|
|
|
|
leader: this.userId,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}).finish();
|
|
|
|
|
|
|
|
this.socket.send(bytes);
|
2021-12-12 16:56:26 +01:00
|
|
|
}
|
|
|
|
|
2021-12-15 14:48:45 +01:00
|
|
|
public emitFollowConfirmation(): void {
|
|
|
|
if (!this.userId) {
|
2021-12-12 16:56:26 +01:00
|
|
|
return;
|
|
|
|
}
|
2022-01-03 15:23:28 +01:00
|
|
|
|
|
|
|
const bytes = ClientToServerMessageTsProto.encode({
|
|
|
|
message: {
|
|
|
|
$case: "followConfirmationMessage",
|
|
|
|
followConfirmationMessage: {
|
|
|
|
leader: get(followUsersStore)[0],
|
|
|
|
follower: this.userId,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}).finish();
|
|
|
|
|
|
|
|
this.socket.send(bytes);
|
2021-12-12 16:56:26 +01:00
|
|
|
}
|
|
|
|
|
2021-12-15 14:48:45 +01:00
|
|
|
public emitFollowAbort(): void {
|
2021-12-24 15:49:25 +01:00
|
|
|
const isLeader = get(followRoleStore) === "leader";
|
2021-12-15 14:48:45 +01:00
|
|
|
const hasFollowers = get(followUsersStore).length > 0;
|
|
|
|
if (!this.userId || (isLeader && !hasFollowers)) {
|
2021-12-12 16:56:26 +01:00
|
|
|
return;
|
|
|
|
}
|
2022-01-03 15:23:28 +01:00
|
|
|
|
|
|
|
const bytes = ClientToServerMessageTsProto.encode({
|
|
|
|
message: {
|
|
|
|
$case: "followAbortMessage",
|
|
|
|
followAbortMessage: {
|
|
|
|
leader: isLeader ? this.userId : get(followUsersStore)[0],
|
|
|
|
follower: isLeader ? 0 : this.userId,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}).finish();
|
|
|
|
|
|
|
|
this.socket.send(bytes);
|
2021-12-12 00:24:39 +01:00
|
|
|
}
|
|
|
|
|
2021-06-25 18:14:40 +02:00
|
|
|
public getAllTags(): string[] {
|
2021-05-20 10:57:36 +02:00
|
|
|
return this.tags;
|
|
|
|
}
|
2021-12-01 16:38:34 +01:00
|
|
|
|
|
|
|
public get userRoomToken(): string | undefined {
|
|
|
|
return this._userRoomToken;
|
|
|
|
}
|
2020-05-08 00:35:36 +02:00
|
|
|
}
|