From 9d93298e6a021daa675d12595edad30d43c64676 Mon Sep 17 00:00:00 2001 From: Brandon Sturgeon Date: Mon, 15 Feb 2021 04:02:21 -0800 Subject: [PATCH] Refactor websocket init --- moon/cfc_chat_transit/server/init.moon | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/moon/cfc_chat_transit/server/init.moon b/moon/cfc_chat_transit/server/init.moon index 2f80c13..3e97c5a 100644 --- a/moon/cfc_chat_transit/server/init.moon +++ b/moon/cfc_chat_transit/server/init.moon @@ -20,19 +20,16 @@ Realm = string.Replace Realm, "\n", "" ChatTransit.Logger = CFCLogger "CFC_ChatTransit" ChatTransit.TeamColorCache = {} +ChatTransit.WebSocket = GWSockets.createWebSocket "ws://127.0.0.1:#{RelayPort}" -hook.Add "PostEntityInit", "CFC_ChatTransit_WSInit", -> +with ChatTransit.WebSocket Logger = ChatTransit.Logger - ChatTransit.WebSocket = GWSockets.createWebSocket "ws://127.0.0.1#{RelayPort}" + \setHeader "Authorization", "Bearer #{RelayPassword}" + \onConnected -> Logger\info "Established websocket connection" + \onDisconnected -> Logger\warn "Lost websocket connection!" + \onError (message) -> Logger\error "Websocket Error!", message + \open! - with ChatTransit.WebSocket - \setHeader "Authorization", "Bearer #{RelayPassword}" - \onConnected -> Logger\info "Established websocket connection" - \onDisconnected -> Logger\warn "Lost websocket connection!" - \onError (message) -> Logger\error "Websocket Error!", message - \open! - - nil ChatTransit.GetTeamColorCode = (teamName) => return @TeamColorCache[teamName] if @TeamColorCache[teamName]