API Docs¶
Invenio module for HTML5 server-sent events support.
-
class
invenio_sse.ext.
InvenioSSE
(app=None)[source]¶ Invenio-SSE extension.
Extension initialization.
-
class
invenio_sse.ext.
_SSEState
(app)[source]¶ SSE state accessible via
proxies.current_sse
.Initialize state.
-
publish
(data, type_=None, id_=None, retry=None, channel='sse')[source]¶ Publish data as a server-sent event.
Parameters: - data – Event data, any object serialize to JSON.
- type – Optional type of the event.
- id – Optional event ID to set the EventSource object’s last event ID value.
- retry – Optional reconnection time to use when attempting to send the event.
- channel – Optional channel to direct events to different clients,
by defaul
sse
.
-
Utilities¶
Utils.
-
invenio_sse.utils.
format_sse_event
(event)[source]¶ Encode a new event following SSE standard.
event: "New message"\n id: 12345\n data: {\n data: "msg": "hello world",\n data: }\n retry: 10000\n\n
Parameters: event – A dictionary containing the keys data
,id
,retry
andevent
. Onlydata
field is mandatory, all the other fields are optional.Returns: A formatted SSE message.