DataPipe
Extends:
Direct Subclass:
Provides access to methods for managing an outgoing or an incoming data pipe DataPipe objects are obtained by calling the {Session#createDataPipe} method or handling the incomingDataPipe event of a connected {Session} instance.
DataPipe allows data interchange between N users when pipe reaches 'connected' status.
A DataPipe is identified by a label: shared string that will be available to any peer.
This class emits next events:
- 'data'
- 'data-with-info'
- 'status'
'data' event:
- Received data from another pipe peer.
- Payload is a string that represents received data.
'data-with-info' event:
- Received data with aditional info from another peer.
- Event payload has next structure: {data: <String>, from: <sender>, ts: <timestamp>}
'status' event:
- Pipe status changed.
- Payload is a DataPipe.STATUS element
Example:
How to create a DataPipe
pipe = session.createDataPipe(to)
pipe.on("data", function(dt) {
console.log("received data", dt);
});
pipe.when(DataPipeStatus.DISCONNECTED).then(function(){...});
pipe.connect().then(function() {
// Connecting code
console.log("pipe connected, ready to send/receive");
pipe.send("Hello world")
});
Member Summary
Public Members | ||
public |
[priv.id]: * |
|
public |
|
|
public |
[priv.label]: * |
|
public |
|
|
public |
[priv.stack]: * |
|
public |
|
|
public |
[priv.type]: * |
|
public get |
Gets a unique identifier for the pipe |
|
public get |
Return label associated with this DataPipe. |
|
public get |
Gets the identities of the peers attached to this pipe |
|
public get |
Gets the identities of the remote peers attached to this pipe |
|
public get |
Retrieves the current status of this pipe. |
|
public get |
type: DataPipe.TYPE Gets pipe type |
Method Summary
Public Methods | ||
public |
addParticipant(identity: String): Promise<DataPipe, Error> Adds a participant to this pipe. |
|
public |
Attempts to reach the pipe recipient and establish a connection. |
|
public |
disconnect(): Promise<DataPipe, Error> Ends an active pipe. |
|
public |
Called when a user does not wish to accept an incoming pipe. |
|
public |
removeParticipant(identity: String): Promise<DataPipe, Error> Removes a participant from this pipe. |
|
public |
Sends data to the DataPipe recipients |
|
public |
when(status: DataPipeStatus): Promise<DataPipe, Error> Returns a Promise resolved when pipe reaches provided state |
Public Members
public [priv.id]: * source
public [priv.internalId]: * source
public [priv.label]: * source
public [priv.participants]: * source
public [priv.stack]: * source
public [priv.status]: * source
public [priv.type]: * source
public get label: String source
Return label associated with this DataPipe. Requires DataPipe to be connected
public get participants: Array<String> source
Gets the identities of the peers attached to this pipe
Public Methods
public addParticipant(identity: String): Promise<DataPipe, Error> source
Adds a participant to this pipe.
When this method fails returned {Promise} is rejected with one of next {Error}
- 'unimplemented'
- 'not allowed'
- 'invalid-state' error when called on "disconnected" state
Params:
Name | Type | Attribute | Description |
identity | String | participant to add |
public connect(): Promise<DataPipe, Error> source
Attempts to reach the pipe recipient and establish a connection. For an incoming pipe, calling this method explicitly joins/accepts the pipe.
When this method fails returned {Promise} is rejected with one of next {Error}
- 'unimplemented'
- 'invalid-state' error when called on state different than "unconnected" state
- 'disconnected' pipe reaches disconnected state without being connected
public disconnect(): Promise<DataPipe, Error> source
Ends an active pipe.
When this method fails returned {Promise} is rejected with one of next {Error}
- 'unimplemented'
- 'invalid-state' error when called on state different than "connected" state
public reject(): Promise<DataPipe, Error> source
Called when a user does not wish to accept an incoming pipe.
When this method fails returned {Promise} is rejected with one of next {Error}
- 'unimplemented'
- 'invalid-state' error when called on state different than "unconnected" state
- 'invalid-state' error when called on outgoing pipes
public removeParticipant(identity: String): Promise<DataPipe, Error> source
Removes a participant from this pipe.
When this method fails returned {Promise} is rejected with one of next {Error}
- 'unimplemented'
- 'not allowed'
- 'invalid-state' error when called on "disconnected" state
Params:
Name | Type | Attribute | Description |
identity | String | participant to remove |
public send(data: String): Promise<DataPipe, Error> source
Sends data to the DataPipe recipients
When this method fails returned {Promise} is rejected with one of next {Error}
- 'unimplemented'
- 'invalid-state' error when called on state different than "connected" state
Params:
Name | Type | Attribute | Description |
data | String | data to send |
public when(status: DataPipeStatus): Promise<DataPipe, Error> source
Returns a Promise resolved when pipe reaches provided state
- "unreachable state" pipe can not reach this state
- "invalid state" pipe state changed to an state that makes impossible reach desired state.
Params:
Name | Type | Attribute | Description |
status | DataPipeStatus | desired state |