billstclair/elm-mastodon-websocket/1.0.0

NOTE: the latest version is 2.0.15

Mastodon.WebSocket

The WebSocket API for the Mastodon Social Network.

Types

= UserStream
| PublicStream
| LocalStream
| PublicHashtagStream String
| LocalHashtagStream String
| ListStream String
| DirectStream
| GroupStream String

Stream types.

Use streamingUrl to convert one of these into a url string.

The String arg to PublicHashtagStream and LocalHashtagStream is a hashtag.

The String arg to ListStream is a list ID.

The String arg to GroupStream is a group ID. Groups are currently supported only by the Gab server code.

type Event
= NoEvent
| UpdateEvent Status
| NotificationEvent Notification
| DeleteEvent String
| FiltersChangedEvent
| ConnectedEvent String
| ReconnectedEvent String
| UnknownEvent String
| ClosedEvent String

An event received over the websocket.

NoEvent, UpdateEvent, NotificationEvent, DeleteEvent, and FiltersChangedEvent come over the wire as specified at https://docs.joinmastodon.org/api/streaming.

ConnectedEvent is delivered as soon as the initial connection is made, right after your send a PortFunnels.WebSocket.makeOpen message over the socket.

ReconnectedEvent is delivered if the connection is lost and auto-reconnected.

ClosedEvent is delivered if the reconnection fails, or you explicitly send a PortFunnels.WebSocket.makeClose message.

Functions

streamUrl : String -> Maybe String -> StreamType -> String

Convert a streaming API (e.g. "rss://mastodon.social"), access token, and stream type into a URL for the WebSocket connection.

streamUrl streaming_api accessToken streamType

If accessToken is Nothing, will attempt to connect without authentication. This works for the following StreamTypes: [TODO]

open : State msg -> String -> String -> Cmd msg

Open a WebSocket connection.

open state key url

state is initially the result of WebSocket.PortFunnels.initialState.

key is a unique key string.

url is the result of a call to streamUrl.

close : State msg -> String -> Cmd msg

Close a socket opened with open.

close state key
decodeEvent : String -> Result Error Event

Decode a string from the WebSocket stream.

The JSON decoder for a non-colon event.

You'll usually use decodeEvent on the string that comes over the WebSocket."