From ab6fe5dbe625bca862558557224d6b5f8d2e5f1d Mon Sep 17 00:00:00 2001 From: yipstanley Date: Mon, 11 Feb 2019 00:28:48 -0500 Subject: asdfkjlasdfljkagit add -A! --- src/Utils.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/Utils.ts') 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(socket: Socket | SocketIOClient.Socket, message: Message, args: T) { + socket.emit(message.Message, args); + } + + public static EmitCallback(socket: Socket | SocketIOClient.Socket, message: Message, args: T, fn: (args: any) => any) { + socket.emit(message.Message, args, fn); + } + + public static AddServerHandler(socket: Socket, message: Message, handler: (args: T) => any) { + socket.on(message.Message, handler); + } + + public static AddServerHandlerCallback(socket: Socket, message: Message, 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 -- cgit v1.2.3-70-g09d2