Skip to content

Commit

Permalink
Refactor websocket init
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonsturgeon committed Feb 15, 2021
1 parent ea7830e commit 9d93298
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions moon/cfc_chat_transit/server/init.moon
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 9d93298

Please sign in to comment.