Class: ServerConnection

ServerConnection()

new ServerConnection()

ServerConnection encapsulates a websocket connection to the server and all the associated streams.
Source:

Members

down :Object.<string, Stream>

The set of all down streams, indexed by their id.
Type:
Source:

group :string

The group that we have joined, or null if we haven't joined yet.
Type:
  • string
Source:

(constant) id :string

The id of this connection.
Type:
  • string
Source:

onchat

onchat is called whenever a new chat message is received.
Source:

onclose

onclose is called when the connection is closed
Source:

onconnected

onconnected is called when the connection has been established
Source:

ondownstream

ondownstream is called whenever a new down stream is added. It should set up the stream's callbacks; actually setting up the UI should be done in the stream's ondowntrack callback.
Source:

onfiletransfer

onfiletransfer is called whenever a peer offers a file transfer. If the transfer is accepted, it should set up the file transfer callbacks and return immediately. It may also throw an exception in order to reject the file transfer.
Source:

onjoined

onjoined is called whenever we join or leave a group or whenever the permissions we have in a group change. kind is one of 'join', 'fail', 'change' or 'leave'.
Source:

onpeerconnection

onpeerconnection is called before we establish a new peer connection. It may either return null, or a new RTCConfiguration that overrides the value obtained from the server.
Source:

onuser

onuser is called whenever a user in the group changes. The users array has already been updated.
Source:

onusermessage

onusermessage is called when an application-specific message is received. Id is null when the message originated at the server, a user-id otherwise. 'kind' is typically one of 'error', 'warning', 'info' or 'mute'. If 'id' is non-null, 'privileged' indicates whether the message was sent by an operator.
Source:

permissions :Array.<string>

The permissions granted to this connection.
Type:
  • Array.<string>
Source:

rtcConfiguration :RTCConfiguration

The ICE configuration used by all associated streams.
Type:
  • RTCConfiguration
Source:

socket :WebSocket

The underlying websocket.
Type:
  • WebSocket
Source:

transferredFiles :Object.<string, TransferredFile>

The set of files currently being transferred.
Type:
Source:

up :Object.<string, Stream>

The set of all up streams, indexed by their id.
Type:
Source:

userdata

userdata is a convenient place to attach data to a ServerConnection. It is not used by the library.
Source:

username :string

The username we joined as.
Type:
  • string
Source:

users :Object.<string, user>

The set of users in this group, including ourself.
Type:
  • Object.<string, user>
Source:

version :string

The negotiated protocol version.
Type:
  • string
Source:

Methods

chat(kind, dest, value)

chat sends a chat message to the server. The server will normally echo the message back to the client.
Parameters:
Name Type Description
kind string - The kind of message, either '', 'me' or an application-specific type.
dest string The id to send the message to, empty for broadcast.
value string The text of the message.
Source:

close()

close forcibly closes a server connection. The onclose callback will be called when the connection is effectively closed.
Source:

connect(url) → {Promise.<ServerConnection>}

connect connects to the server.
Parameters:
Name Type Description
url string The URL to connect to.
Source:
Returns:
Type
Promise.<ServerConnection>

fileTransfer(id, username, message)

fileTransfer handles a usermessage of kind 'filetransfer'. Don't call this, it is called automatically as needed.
Parameters:
Name Type Description
id string
username string
message object
Source:

findByLocalId(localId) → {Stream}

findByLocalId finds an active connection with the given localId. It returns null if none was find.
Parameters:
Name Type Description
localId string
Source:
Returns:
Type
Stream

getRTCConfiguration() → {RTCConfiguration}

getRTCConfiguration returns the RTCConfiguration that should be used with this peer connection. This usually comes from the server, but may be overridden by the onpeerconnection callback.
Source:
Returns:
Type
RTCConfiguration

getTransferredFile(userid, fileid, up) → {TransferredFile}

Retrieve a transferred file from the transferredFiles dictionary.
Parameters:
Name Type Description
userid string
fileid string
up boolean
Source:
Returns:
Type
TransferredFile

gotAbort(id)

gotAbort is called when we receive an abort message from the server. Don't call this.
Parameters:
Name Type Description
id string
Source:

gotAnswer(id, sdp)

gotAnswer is called when we receive an answer from the server. Don't call this.
Parameters:
Name Type Description
id string
sdp string
Source:

gotClose(id)

gotClose is called when we receive a close request from the server. Don't call this.
Parameters:
Name Type Description
id string
Source:

gotOffer(id, label, source, username, sdp, replace)

gotOffer is called when we receive an offer from the server. Don't call this.
Parameters:
Name Type Description
id string
label string
source string
username string
sdp string
replace string
Source:

gotRemoteIce(id, candidate)

gotRemoteIce is called when we receive an ICE candidate from the server. Don't call this.
Parameters:
Name Type Description
id string
candidate RTCIceCandidate
Source:

gotRenegotiate(id)

gotRenegotiate is called when we receive a renegotiation request from the server. Don't call this.
Parameters:
Name Type Description
id string
Source:

groupAction(kind, dataopt)

groupAction sends a request to act on the current group.
Parameters:
Name Type Attributes Description
kind string
data any <optional>
Source:

join(group, username, credentials, dataopt)

join requests to join a group. The onjoined callback will be called when we've effectively joined.
Parameters:
Name Type Attributes Description
group string The name of the group to join.
username string the username to join as.
credentials string | Object password or authServer.
data Object.<string, any> <optional>
the initial associated data.
Source:

leave(group)

leave leaves a group. The onjoined callback will be called when we've effectively left.
Parameters:
Name Type Description
group string The name of the group to join.
Source:

newUpStream(localIdopt) → {Stream}

newUpStream requests the creation of a new up stream.
Parameters:
Name Type Attributes Description
localId string <optional>
- The local id of the stream to create. If a stream already exists with the same local id, it is replaced with the new stream.
Source:
Returns:
Type
Stream

request(what)

request sets the list of requested tracks
Parameters:
Name Type Description
what Object.<string, Array.<string>> - A dictionary that maps labels to a sequence of 'audio', 'video' or 'video-low. An entry with an empty label '' provides the default.
Source:

send(m)

send sends a message to the server.
Parameters:
Name Type Description
m message the message to send.
Source:

sendFile(id, file)

Initiate a file upload. This will cause the onfiletransfer callback to be called, at which point you should set up the onevent callback.
Parameters:
Name Type Description
id string
file File
Source:

userAction(kind, dest, valueopt)

userAction sends a request to act on a user.
Parameters:
Name Type Attributes Description
kind string One of "op", "unop", "kick", "present", "unpresent".
dest string The id of the user to act upon.
value any <optional>
An action-dependent parameter.
Source:

userMessage(kind, dest, valueopt, noechoopt)

userMessage sends an application-specific message to a user. This is similar to a chat message, but is not saved in the chat history.
Parameters:
Name Type Attributes Description
kind string The kind of application-specific message.
dest string The id to send the message to, empty for broadcast.
value unknown <optional>
An optional parameter.
noecho boolean <optional>
If set, don't echo back the message to the sender.
Source: