Skip to content

Instantly share code, notes, and snippets.

@SReject
Last active July 23, 2016 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SReject/554ff1cca74b780ce7997bdb87aa98b2 to your computer and use it in GitHub Desktop.
Save SReject/554ff1cca74b780ce7997bdb87aa98b2 to your computer and use it in GitHub Desktop.

Authorization

Instead of requiring fetching an authkey from a web endpoint, authorization should take place within the websocket's initial HTTP request via usual methods such as OAuth or cookie verification.

Joining a Chat

If the channel id does not exist an error should be returned in the reply.
If a join method has already succeeded for the channel id on the connection an error should be returned in the reply

// Client:
{
    "type": "method",
    "method": "join",
    "arguments": _channel_id_,
    "id": _method_id_
}

// Server:
{
    "type": "reply",
    "error": null,
    "data": {
        "authenticated": true,
        "roles": ["Owner"]
    },
    "id", _method_id_
}

Leaving a chat

If the channel id does not exist an error should be returned in the reply.
If the channel is not joined for the connection an error should be returned in the reply.

// Client
{
    "type": "method",
    "method": "leave",
    "arguments": [_channel_id_],
    "id": _method_id_
}

// server
{
    "type": "reply",
    "error": null,
    "data": null,
    "id": _method_id_
}

Interacting with Chat

Once a channel has been joined, all other methods' first argument* is the channel id inwhich to interact with.
If the channel id does not exist an error should be returned in the reply.
If the channel id has not previously been joined for the connection an error should be returned.

{"type": "method", "method": "msg", "arguments": [_channel_id_, "Hello world :)"], "id": _method_id_}
{"type": "method", "method": "vote", "arguments": [_channel_id_, 0], "id": _method_id_}

Events from chat

All events are required to contain a channel property identifying which channel the event took place on*

{
   "channel": _channel_id_,
   "id": _event_id_,
   "user_name": "Username",
   "user_id": 12345,
   "user_roles": [
      "User"
   ],
   "message": {
      "message": [{
        "type": "text",
        "data": "Hello! ",
        "text": "Hello! "
     }],
      "meta": {}
   }
}

*: Potentially, this could not be required for whispers as its been stated that beam would like to de-couple whispers from a specific channel's scopes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment