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

Commit a57191b

Browse files
committed
Move task based API into WebSocket.LowLevel
The primitives are needed for stuff like Phoenix Channels, where you want to manage the connections by hand in your own effect manager.
1 parent 3eb0879 commit a57191b

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/WebSocket.elm renamed to src/WebSocket/LowLevel.elm

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,43 @@
1-
module WebSocket
1+
module WebSocket.LowLevel
22
( WebSocket
3-
, Message
43
, open, Settings
54
, send, close, closeWith
65
, bytesQueued
76
)
87
where
9-
{-|
8+
{-| Low-level bindings to [the JavaScript API for web sockets][ws]. This is
9+
useful primarily for making effect modules like [WebSocket](/WebSocket). So
10+
if you happen to be the creator of Elixir’s Phoenix framework, and you want
11+
it to be super easy to use channels, this module will help you make a really
12+
nice subscription-based API. If you are someone else, you probably do not want
13+
these things.
1014
11-
# WebSockets and Messages
12-
@docs WebSocket, Message
15+
[ws]: https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
16+
17+
# WebSockets
18+
@docs WebSocket
1319
1420
# Using WebSockets
1521
@docs open, Settings, send, close, closeWith, bytesQueued
1622
1723
-}
1824

1925
import Native.WebSocket
26+
import Task exposing (Task)
27+
2028

29+
{-| A value representing an open connection to a server. Normally every single
30+
HTTP request must establish a connection with the server, but here we just set
31+
it up once and keep using it. This means it is faster to send messages.
2132
33+
There is a request/response pattern for all HTTP requests. Client asks for
34+
something, server gives some response. With websockets, you can drive messages
35+
from the server instead.
36+
-}
2237
type WebSocket = WebSocket
2338

2439

25-
{-|
40+
{-| Attempt to open a connection to a particular URL.
2641
-}
2742
open : String -> Settings -> Task BadOpen WebSocket
2843
open =

0 commit comments

Comments
 (0)