aboutsummaryrefslogtreecommitdiff
path: root/src/Utils.ts
diff options
context:
space:
mode:
authoryipstanley <stanley_yip@brown.edu>2019-02-11 00:28:48 -0500
committeryipstanley <stanley_yip@brown.edu>2019-02-11 00:28:48 -0500
commitab6fe5dbe625bca862558557224d6b5f8d2e5f1d (patch)
treeb85114a770ed44a6ac2120dbb8dcfc0bdc48e5ff /src/Utils.ts
parent5d081dc8ea638f9729058bfe7a310cebbd9f5581 (diff)
asdfkjlasdfljkagit add -A!
Diffstat (limited to 'src/Utils.ts')
-rw-r--r--src/Utils.ts18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/Utils.ts b/src/Utils.ts
index cc1d8f6c6..f735ddc73 100644
--- a/src/Utils.ts
+++ b/src/Utils.ts
@@ -1,5 +1,7 @@
import v4 = require('uuid/v4');
import v5 = require("uuid/v5");
+import { Socket } from 'socket.io';
+import { Message } from './server/Message';
export class Utils {
@@ -19,4 +21,20 @@ export class Utils {
return { scale, translateX, translateY };
}
+
+ public static Emit<T>(socket: Socket | SocketIOClient.Socket, message: Message<T>, args: T) {
+ socket.emit(message.Message, args);
+ }
+
+ public static EmitCallback<T>(socket: Socket | SocketIOClient.Socket, message: Message<T>, args: T, fn: (args: any) => any) {
+ socket.emit(message.Message, args, fn);
+ }
+
+ public static AddServerHandler<T>(socket: Socket, message: Message<T>, handler: (args: T) => any) {
+ socket.on(message.Message, handler);
+ }
+
+ public static AddServerHandlerCallback<T>(socket: Socket, message: Message<T>, handler: (args: [T, (res: any) => any]) => any) {
+ socket.on(message.Message, (arg: T, fn: (res: any) => any) => handler([arg, fn]));
+ }
} \ No newline at end of file