Class ServerConnection
Defined in: protocol.js.
Constructor Attributes | Constructor Name and Description |
---|---|
ServerConnection encapsulates a websocket connection to the server and
all the associated streams.
|
Field Attributes | Field Name and Description |
---|---|
The set of all down streams, indexed by their id.
|
|
The group that we have joined, or null if we haven't joined yet.
|
|
The id of this connection.
|
|
onchat is called whenever a new chat message is received.
|
|
onclose is called when the connection is closed
|
|
onconnected is called when the connection has been established
|
|
ondownstream is called whenever a new down stream is added.
|
|
onfiletransfer is called whenever a peer offers a file transfer.
|
|
onjoined is called whenever we join or leave a group or whenever the
permissions we have in a group change.
|
|
onpeerconnection is called before we establish a new peer connection.
|
|
onuser is called whenever a user in the group changes.
|
|
onusermessage is called when an application-specific message is
received.
|
|
The permissions granted to this connection.
|
|
The ICE configuration used by all associated streams.
|
|
The underlying websocket.
|
|
The set of files currently being transferred.
|
|
The set of all up streams, indexed by their id.
|
|
userdata is a convenient place to attach data to a ServerConnection.
|
|
The username we joined as.
|
|
The set of users in this group, including ourself.
|
|
The negotiated protocol version.
|
Method Attributes | Method Name and Description |
---|---|
close()
close forcibly closes a server connection.
|
|
connect(url)
connect connects to the server.
|
|
fileTransfer(id, username, message)
fileTransfer handles a usermessage of kind 'filetransfer'.
|
|
getTransferredFile(userid, fileid, up)
Retrieve a transferred file from the transferredFiles dictionary.
|
|
send(m)
send sends a message to the server.
|
|
sendFile(id, file)
Initiate a file upload.
|
Class Detail
ServerConnection()
ServerConnection encapsulates a websocket connection to the server and
all the associated streams.
Field Detail
down
The set of all down streams, indexed by their id.
group
The group that we have joined, or null if we haven't joined yet.
id
The id of this connection.
onchat
onchat is called whenever a new chat message is received.
onclose
onclose is called when the connection is closed
onconnected
onconnected is called when the connection has been established
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.
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.
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'.
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.
onuser
onuser is called whenever a user in the group changes. The users
array has already been updated.
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.
permissions
The permissions granted to this connection.
rtcConfiguration
The ICE configuration used by all associated streams.
socket
The underlying websocket.
transferredFiles
The set of files currently being transferred.
up
The set of all up streams, indexed by their id.
userdata
userdata is a convenient place to attach data to a ServerConnection.
It is not used by the library.
username
The username we joined as.
users
The set of users in this group, including ourself.
version
The negotiated protocol version.
Method Detail
close()
close forcibly closes a server connection. The onclose callback will
be called when the connection is effectively closed.
{Promise}
connect(url)
connect connects to the server.
- Parameters:
- {string} url
- - The URL to connect to.
- Returns:
- {Promise
}
fileTransfer(id, username, message)
fileTransfer handles a usermessage of kind 'filetransfer'. Don't call
this, it is called automatically as needed.
- Parameters:
- {string} id
- {string} username
- {object} message
{TransferredFile}
getTransferredFile(userid, fileid, up)
Retrieve a transferred file from the transferredFiles dictionary.
- Parameters:
- {string} userid
- {string} fileid
- {boolean} up
- Returns:
- {TransferredFile}
send(m)
send sends a message to the server.
- Parameters:
- {message} m
- - the message to send.
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:
- {string} id
- {File} file