Skip to content

Commit

Permalink
dev(WebSocket): support onOpen, onClose
Browse files Browse the repository at this point in the history
based on elm-lang/websocket#19 - merged with binary data support
  • Loading branch information
Namek committed Jul 14, 2017
1 parent e5f84c4 commit 6cca059
Show file tree
Hide file tree
Showing 2 changed files with 173 additions and 103 deletions.
22 changes: 21 additions & 1 deletion client/src/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ updateSystemStats systems index entitiesCount maxEntitiesCount =
type Msg
= Input String
| Send
| OnWebsocketOpen String
| OnWebsocketClose String
| NewNetworkMessage MessageData
| Msg_Unknown
| Msg_OnAddedSystem Int String (Maybe BitVector) (Maybe BitVector) (Maybe BitVector)
Expand All @@ -125,6 +127,20 @@ update msg model =
, WebSocket.send websocketUrl (ArrayBuffer (stringToBufferArray input))
)

OnWebsocketOpen url ->
let
_ =
Debug.log "websocket open" url
in
model ! []

OnWebsocketClose url ->
let
_ =
Debug.log "websocket close" url
in
model ! []

NewNetworkMessage (String str) ->
{ model | messages = str :: messages } ! []

Expand Down Expand Up @@ -289,7 +305,11 @@ deserializePacket objModelNodes valueTrees componentTypes bytes =

subscriptions : Model -> Sub Msg
subscriptions model =
WebSocket.listen websocketUrl NewNetworkMessage
Sub.batch
[ WebSocket.listen websocketUrl NewNetworkMessage
, WebSocket.onOpen OnWebsocketOpen
, WebSocket.onClose OnWebsocketClose
]



Expand Down
Loading

0 comments on commit 6cca059

Please sign in to comment.