Skip to content
This repository has been archived by the owner on May 5, 2020. It is now read-only.

Provide console feedback on improper protocol #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/WebSocket.elm
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ send one message and then closed. Not good!
-}
send : String -> String -> Cmd msg
send url message =
command (Send url message)
command (Send (checkProtocol url) message)


cmdMap : (a -> b) -> MyCmd a -> MyCmd b
Expand Down Expand Up @@ -80,7 +80,7 @@ connection is down are queued and will be sent as soon as possible.
-}
listen : String -> (String -> msg) -> Sub msg
listen url tagger =
subscription (Listen url tagger)
subscription (Listen (checkProtocol url) tagger)


{-| Keep a connection alive, but do not report any messages. This is useful
Expand All @@ -96,7 +96,7 @@ connection is down are queued and will be sent as soon as possible.
-}
keepAlive : String -> Sub msg
keepAlive url =
subscription (KeepAlive url)
subscription (KeepAlive (checkProtocol url))


subMap : (a -> b) -> MySub a -> MySub b
Expand Down Expand Up @@ -349,3 +349,14 @@ closeConnection connection =

Connected socket ->
WS.close socket


-- DEVELOPER FEEDBACK

checkProtocol : String -> String
checkProtocol url =
if String.left 5 url == "ws://" || String.left 6 url == "wss://" then
url
else
Debug.log ("WARNING: Websocket URL does not start with ws:// or wss://."
++ " You probably want to change that.") url