aboutsummaryrefslogtreecommitdiff
path: root/src/Utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/Utils.ts')
-rw-r--r--src/Utils.ts28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/Utils.ts b/src/Utils.ts
index 38a59d524..08ddfa817 100644
--- a/src/Utils.ts
+++ b/src/Utils.ts
@@ -1,6 +1,8 @@
import * as v4 from 'uuid/v4';
import * as v5 from 'uuid/v5';
import { ColorResult } from 'react-color';
+//import { Socket } from '../node_modules/socket.io-client';
+import { Socket } from '../node_modules/socket.io/dist/index';
import * as rp from 'request-promise';
import { DocumentType } from './client/documents/DocumentTypes';
import { Colors } from './client/views/global/globalEnums';
@@ -54,6 +56,14 @@ export namespace Utils {
return v5(seed, v5.URL);
}
+ export function GenerateMongoId(id: string): string {
+ return id.length !== 36 ? Utils.GenerateDeterministicGuid(id) : id;
+ }
+
+ export function GuestID() {
+ return '__guest__';
+ }
+
/**
* Uploads an image buffer to the server and stores with specified filename. by default the image
* is stored at multiple resolutions each retrieved by using the filename appended with _o, _s, _m, _l (indicating original, small, medium, or large)
@@ -397,14 +407,14 @@ export namespace Utils {
};
}
- export function Emit<T>(socket: SocketIOClient.Socket, message: Message<T>, args: T) {
+ export function Emit<T>(socket: { emit: (msg: string, args: T) => void }, message: Message<T>, args: T) {
log('Emit', message.Name, args, false);
socket.emit(message.Message, args);
}
- export function EmitCallback<T>(socket: SocketIOClient.Socket, message: Message<T>, args: T): Promise<any>;
- export function EmitCallback<T>(socket: SocketIOClient.Socket, message: Message<T>, args: T, fn: (args: any) => any): void;
- export function EmitCallback<T>(socket: SocketIOClient.Socket, message: Message<T>, args: T, fn?: (args: any) => any): void | Promise<any> {
+ export function EmitCallback<T>(socket: Socket, message: Message<T>, args: T): Promise<any>;
+ export function EmitCallback<T>(socket: Socket, message: Message<T>, args: T, fn: (args: any) => any): void;
+ export function EmitCallback<T>(socket: Socket, message: Message<T>, args: T, fn?: (args: any) => any): void | Promise<any> {
log('Emit', message.Name, args, false);
if (fn) {
socket.emit(message.Message, args, loggingCallback('Receiving', fn, message.Name));
@@ -413,20 +423,20 @@ export namespace Utils {
}
}
- export function AddServerHandler<T>(socket: SocketIOClient.Socket, message: Message<T>, handler: (args: T) => any) {
+ export function AddServerHandler<T>(socket: { on: (event: string, cb: (args: any) => void) => void }, message: Message<T>, handler: (args: T) => any) {
socket.on(message.Message, loggingCallback('Incoming', handler, message.Name));
}
- export function AddServerHandlerCallback<T>(socket: SocketIOClient.Socket, message: Message<T>, handler: (args: [T, (res: any) => any]) => any) {
+ export function AddServerHandlerCallback<T>(socket: { on: (event: string, cb: (arg: T, fn: (res: any) => any) => void) => void }, message: Message<T>, handler: (args: [T, (res: any) => any]) => any) {
socket.on(message.Message, (arg: T, fn: (res: any) => any) => {
log('S receiving', message.Name, arg, true);
handler([arg, loggingCallback('S sending', fn, message.Name)]);
});
}
- export type RoomHandler = (socket: SocketIOClient.Socket, room: string) => any;
- export type UsedSockets = SocketIOClient.Socket;
+ export type RoomHandler = (socket: Socket, room: string) => any;
+ export type UsedSockets = Socket;
export type RoomMessage = 'create or join' | 'created' | 'joined';
- export function AddRoomHandler(socket: SocketIOClient.Socket, message: RoomMessage, handler: RoomHandler) {
+ export function AddRoomHandler(socket: Socket, message: RoomMessage, handler: RoomHandler) {
socket.on(message, (room: any) => handler(socket, room));
}
}