Websocket Services

The WebSocketServer accepts websocket connections from browsers and will provide different services on it.

By default, the server listens on port 8101. Deployment should be done on the same hostname as the primary UI, to ensure that authentication cookies will be sent with the websocket request.

Messages passed back and forth follow the common format:

{
   "channel": "my_name",
   "payload": { "data": "here" }
}
class WebSocketServer(loop=None)[source]

A websocket server that routes messages to services.

on_connect(ws, user)[source]

Call on_connect hook on configured services.

on_message(ws, user, message)[source]

Call on_message hook on configured services.

on_disconnect(ws, user)[source]

Call on_disconnect hook on configured services.

handler(ws, path)[source]

Handle websocket connections.

Services

class Notifier(server=None)[source]

Notification broadcast server.

This service relays notifications on the notifications channel.

Example message from the server (including channel info):

{
    "channel": "notifications",
    "payload": {
        "category": "success",
        "last": {
            "category": "success",
            "data": {"_cls": "Notification", "_id": "585a88b208b199f61004d968",
                     "actions": [], "category": 10, "changed_dt": "2016-12-21T14:50:42",
                     "created_dt": "2016-12-21T14:50:42", "message": "Hello, World!"},
            "id": "585a88b208b199f61004d968",
            "is_read": false,
            "label": "Hello, World!",
            "metainfo": {"changedDatetime": "2016-12-21T14:50:42", "changedUser": null,
                         "createdDatetime": "2016-12-21T14:50:42", "createdUser": null}
        },
        "unread": 3
    }
}

This service does not expect any messages from the client.

classmethod notify(notification)[source]

Queue a new notification.

on_broadcast(ws, user, data)[source]

Modify a broadcast message for each individual user.

on_connect(ws, user)[source]

Send current unread notification count when a new user connects.

Example message:

{
    "unread": 3,
    "category": "success"
}
run()[source]

Listen to new notifications and broadcast them upon arrival.

class Clipboard(server=None)[source]

Clipboard server.

This service provides a synchronized clipboard for each user.

clipboard_add(user, data)[source]

Add a new clipboard entry with data.

Parameters

data – Raw data to be added for this entry.

Returns

New clipboard with added entry.

clipboard_flush(user, data)[source]

Clear the clipboard.

Any arguments supplied to this method will be ignored. :return: Freshly emptied clipboard (an empty list).

clipboard_load(user, data)[source]

Add references to models to the clipboard.

Parameters

data (dict) – A dict with model and ids.

clipboard_remove(user, data)[source]

Remove a clipboard entry.

Parameters

data – Should be an integer ID for a clipboard entry.

Returns

New clipboard with entry removed.

on_connect(ws, user)[source]

Send current clipboard state to user when connected.

on_message(ws, user, message)[source]

Receive a clipboard command from the user.

Message should be in the format:

{
    "action": "action_name",
    "data": "action_data"
}

Where action_name is one of:

run()[source]

Run the clipboard service.