billstclair / elm-mastodon-websocket / Mastodon.WebSocket

The WebSocket API for the Mastodon Social Network.

Types


type StreamType
    = UserStream
    | PublicStream
    | LocalStream
    | ProStream
    | 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 Mastodon.Entity.Status
    | NotificationEvent Mastodon.Entity.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 : Mastodon.PortFunnels.State msg -> String -> String -> Platform.Cmd.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 : Mastodon.PortFunnels.State msg -> String -> Platform.Cmd.Cmd msg

Close a socket opened with open.

close state key

decodeEvent : String -> Result Json.Decode.Error Event

Decode a string from the WebSocket stream.

eventDecoder : Json.Decode.Decoder Event

The JSON decoder for a non-colon event.

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