Home Reference Source
import {DataPipe} from '@quobis/sippojs'
public interface | source

DataPipe

Extends:

eventemitter2~EventEmitter2 → DataPipe

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
public
public
public
public
public
public
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

Adds a participant to this pipe.

public

Attempts to reach the pipe recipient and establish a connection.

public

Ends an active pipe.

public

Called when a user does not wish to accept an incoming pipe.

public

Removes a participant from this pipe.

public

Sends data to the DataPipe recipients

public

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 id: String source

Gets a unique identifier for the pipe

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 get remoteParticipants: Array<String> source

Gets the identities of the remote peers attached to this pipe

public get status: DataPipeStatus source

Retrieves the current status of this pipe.

public get type: DataPipe.TYPE source

Gets pipe type

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:

NameTypeAttributeDescription
identity String

participant to add

Return:

Promise<DataPipe, Error>

Resolved with the DataPipe object when invitation sent to new participant or rejected with an {Error}.

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

Return:

Promise<DataPipe, Error>

Resolved with the DataPipe object when pipe reaches "connecting" state or rejected with an {Error}.

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

Return:

Promise<DataPipe, Error>

Resolved with the DataPipe object when pipe reaches "disconnected" state or rejected with an {Error}.

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

Return:

Promise<DataPipe, Error>

Resolved with the DataPipe object when pipe reaches "disconnected" state or rejected with an {Error}.

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:

NameTypeAttributeDescription
identity String

participant to remove

Return:

Promise<DataPipe, Error>

Resolved with the DataPipe object when participant was removed or rejected with an {Error}.

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:

NameTypeAttributeDescription
data String

data to send

Return:

Promise<DataPipe, Error>

Resolved with DataPipe object after data delivery or rejected with an {Error}

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:

NameTypeAttributeDescription
status DataPipeStatus

desired state

Return:

Promise<DataPipe, Error>

Resolved with DataPipe object when pipe reaches provided state or rejected with an {Error}.