Provider
elva.provider
Module holding provider components.
Classes:
-
Connection
–Abstract base class for connection objects.
-
WebsocketConnection
–Websocket connection handling component.
-
WebsocketProvider
–Handler for Y messages sent and received over a websocket connection.
-
ElvaWebsocketProvider
–Handler for Y messages sent and received over a websocket connection.
Connection
Bases: Component
Abstract base class for connection objects.
Methods:
-
send
–Wrapper around the
outgoing.send
method. -
recv
–Wrapper around the
incoming
stream. -
on_recv
–Hook executed on received
data
fromincoming
.
Attributes:
-
connected
(Event
) –Event signaling being connected.
-
disconnected
(Event
) –Event signaling being disconnected.
-
outgoing
(Any
) –Outgoing stream.
-
incoming
(Any
) –Incoming stream.
connected
property
Event signaling being connected.
disconnected
property
Event signaling being disconnected.
outgoing
property
writable
Outgoing stream.
incoming
property
writable
Incoming stream.
send(data)
async
Wrapper around the outgoing.send
method.
Parameters:
Source code in src/elva/provider.py
recv()
async
Wrapper around the incoming
stream.
Source code in src/elva/provider.py
on_recv(data)
async
Hook executed on received data
from incoming
.
This is defined as a no-op and intended to be defined in the inheriting subclass.
Parameters:
Source code in src/elva/provider.py
WebsocketConnection(uri, user=None, password=None, *args, **kwargs)
Bases: Connection
Websocket connection handling component.
Parameters:
-
uri
(str
) –websocket address to connect to.
-
user
(None | str
, default:None
) –username to be sent in the
Basic Authentication
HTTP request header. -
password
(None | str
, default:None
) –password to be sent in the
Basic Authentication
HTTP request header. -
*args
(tuple[Any]
, default:()
) –positional arguments passed to
connect
. -
**kwargs
(dict[Any]
, default:{}
) –keyword arguments passed to
connect
.
Methods:
-
run
–Hook connecting and listening for incoming data.
-
cleanup
–Hook closing the websocket connection gracefully if cancelled.
-
on_connect
–Hook method run on connection.
-
on_exception
–Hook method run on otherwise unhandled invalid URI or invalid HTTP response status.
Attributes:
-
basic_authorization_header
(dict
) –Mapping of
Authorization
HTTP request header to encodedBasic Authentication
information. -
signature
(Signature
) –Object holding the positional and keyword arguments for
connect
. -
options
(dict
) –Mapping of arguments to the signature of
connect
. -
tried_credentials
(bool
) –Flag whether given credentials have already been tried.
Source code in src/elva/provider.py
basic_authorization_header
instance-attribute
Mapping of Authorization
HTTP request header to encoded Basic Authentication
information.
signature = signature(connect).bind(uri, *args, **kwargs)
instance-attribute
Object holding the positional and keyword arguments for connect
.
options = self.signature.arguments
instance-attribute
Mapping of arguments to the signature of connect
.
tried_credentials = False
instance-attribute
Flag whether given credentials have already been tried.
run()
async
Hook connecting and listening for incoming data.
- It retries on HTTP response status other than
101
automatically. - It sends given credentials only after a failed connection attempt.
- It gives the opportunity to update the connection arguments with credentials via the
on_exception
hook, if previously given information result in a failed connection.
Source code in src/elva/provider.py
cleanup()
async
Hook closing the websocket connection gracefully if cancelled.
on_connect()
async
Hook method run on connection.
This is defined as a no-op and supposed to be implemented in the inheriting subclass.
on_exception(exc)
async
Hook method run on otherwise unhandled invalid URI or invalid HTTP response status.
This method defaults to re-raise exc
, is supposed to be implemented in the inheriting subclass and intended to be integrated in a user interface.
Parameters:
-
exc
(InvalidURI | InvalidStatus
) –exception raised by
connect
.
Source code in src/elva/provider.py
WebsocketProvider(ydoc, identifier, server, *args, **kwargs)
Bases: WebsocketConnection
Handler for Y messages sent and received over a websocket connection.
This component follows the Yjs protocol spec.
Parameters:
-
ydoc
(Doc
) –instance if the synchronized Y Document.
-
identifier
(str
) –identifier of the synchronized Y Document.
-
server
(str
) –address of the Y Document synchronizing websocket server.
-
*args
(tuple[Any]
, default:()
) –positional arguments passed to
WebsocketConnection
. -
**kwargs
(dict[Any]
, default:{}
) –keyword arguments passed to
WebsocketConnection
.
Methods:
-
run
–Hook observing changes and handling connection.
-
cleanup
–Hook cancelling the subscription to changes in
ydoc
. -
callback
–Hook called on changes in
ydoc
. -
on_connect
–Hook initializing cross synchronization.
-
on_recv
–Hook called on received
data
over the websocket connection. -
on_sync_step1
–Dispatch method called on received Y sync step 1 message.
-
on_sync_update
–Dispatch method called on received Y sync update message.
-
on_awareness
–Dispatch method called on received Y awareness message.
Attributes:
-
subscription
(Subscription
) –Object holding subscription information to changes in
ydoc
. -
ydoc
(Doc
) –Instance of the synchronized Y Document.
Source code in src/elva/provider.py
subscription
instance-attribute
Object holding subscription information to changes in ydoc
.
ydoc = ydoc
instance-attribute
Instance of the synchronized Y Document.
run()
async
cleanup()
async
callback(event)
Hook called on changes in ydoc
.
When called, the event
data are encoded as Y update message and sent over the established websocket connection.
Parameters:
-
event
(TransactionEvent
) –object holding event information.
Source code in src/elva/provider.py
on_connect()
async
Hook initializing cross synchronization.
When called, it sends a Y sync step 1 message and a Y sync step 2 message with respect to the null state, effectively doing a pro-active cross synchronization.
Source code in src/elva/provider.py
on_recv(data)
async
Hook called on received data
over the websocket connection.
When called, data
is assumed to be a YMessage
and tried to be decoded.
On successful decoding, the payload is dispatched to the appropriate method.
Parameters:
-
data
(bytes
) –message received from the synchronizing server.
Source code in src/elva/provider.py
on_sync_step1(state)
async
Dispatch method called on received Y sync step 1 message.
It answers the message with a Y sync step 2 message according to the Yjs protocol spec.
Parameters:
-
state
(bytes
) –payload included in the incoming Y sync step 1 message.
Source code in src/elva/provider.py
on_sync_update(update)
async
Dispatch method called on received Y sync update message.
The update
gets applied to the internal Y Document instance.
Parameters:
-
update
(bytes
) –payload included in the incoming Y sync update message.
Source code in src/elva/provider.py
on_awareness(state)
async
Dispatch method called on received Y awareness message.
Currently, this is defined as a no-op.
Parameters:
-
state
(bytes
) –payload included in the incoming Y awareness message.
ElvaWebsocketProvider(ydoc, identifier, server, *args, **kwargs)
Bases: WebsocketConnection
Handler for Y messages sent and received over a websocket connection.
This component follows the ELVA protocol.
Parameters:
-
ydoc
(Doc
) –instance if the synchronized Y Document.
-
identifier
(str
) –identifier of the synchronized Y Document.
-
server
(str
) –address of the Y Document synchronizing websocket server.
-
*args
(tuple[Any]
, default:()
) –positional arguments passed to
WebsocketConnection
. -
**kwargs
(dict[Any]
, default:{}
) –keyword arguments passed to
WebsocketConnection
.
Methods:
-
run
–Hook observing changes and handling connection.
-
cleanup
–Hook cancelling the subscription to changes in
ydoc
. -
send
–Send
data
withuuid
prepended. -
callback
–Hook called on changes in
ydoc
. -
on_connect
–Hook initializing cross synchronization.
-
on_recv
–Hook called on received
data
over the websocket connection. -
on_sync_step1
–Hook called on received Y sync step 1 message.
-
on_sync_update
–Hook called on received Y sync update message.
-
on_awareness
–Hook called on received Y awareness message.
Attributes:
-
uuid
(bytes
) –As
ElvaMessage.ID
message encodedidentifier
. -
subscription
(Subscription
) –Object holding subscription information to changes in
ydoc
. -
ydoc
(Doc
) –Instance of the synchronized Y Document.
-
identifier
(str
) –Identifier of the synchronized Y Document.
Source code in src/elva/provider.py
uuid
instance-attribute
As ElvaMessage.ID
message encoded identifier
.
subscription
instance-attribute
Object holding subscription information to changes in ydoc
.
ydoc = ydoc
instance-attribute
Instance of the synchronized Y Document.
identifier = identifier
instance-attribute
Identifier of the synchronized Y Document.
run()
async
cleanup()
async
send(data)
async
callback(event)
Hook called on changes in ydoc
.
When called, the event
data are encoded as Y update message and sent over the established websocket connection.
Parameters:
-
event
(TransactionEvent
) –object holding event information.
Source code in src/elva/provider.py
on_connect()
async
Hook initializing cross synchronization.
When called, it sends a Y sync step 1 message and a Y sync step 2 message with respect to the null state, effectively doing a pro-active cross synchronization.
Source code in src/elva/provider.py
on_recv(data)
async
Hook called on received data
over the websocket connection.
When called, data
is assumed to be an ElvaMessage
and tried to be decoded.
On successful decoding, the payload is dispatched to the appropriate method.
Parameters:
-
data
(bytes
) –message received from the synchronizing server.
Source code in src/elva/provider.py
on_sync_step1(state)
async
Hook called on received Y sync step 1 message.
It answers the message with a Y sync step 2 message according to the ELVA protocol.
Parameters:
-
state
(bytes
) –payload included in the incoming Y sync step 1 message.
Source code in src/elva/provider.py
on_sync_update(update)
async
Hook called on received Y sync update message.
The update
gets applied to the internal Y Document instance.
Parameters:
-
update
(bytes
) –payload included in the incoming Y sync update message.
Source code in src/elva/provider.py
on_awareness(state)
async
Hook called on received Y awareness message.
Currently, this is defined as a no-op.
Parameters:
-
state
(bytes
) –payload included in the incoming Y awareness message.