Constructor
new Session(options) → {ZCC.Session}
Parameters:
Name | Type | Description |
---|---|---|
options |
object | session options. Options can also include player , decoder , recorder and encoder overrides |
- Source:
Returns:
ZCC.Session
instance
- Type
- ZCC.Session
Example
var session = new ZCC.Session({
serverUrl: 'wss://zellowork.io/ws/[yournetworkname]',
username: [username],
password: [password]
channel: [channel],
authToken: [authToken],
maxConnectAttempts: 5,
connectRetryTimeoutMs: 1000,
autoSendAudio: true,
noPersistentPlayer: false
);
Methods
connect(userCallbackopt) → {promise}
Connects to zello server and starts new session
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
userCallback |
function |
<optional> |
null | callback for connection event |
- Source:
Returns:
promise that resolves once session successfully started and rejects on sessions start error
- Type
- promise
Example
// promise
session.connect()
.then(function(result) {
console.log('Session started: ', result)
})
.catch(function(err) {
console.trace(err);
});
// callback
session.connect(function(err, result) {
if (err) {
console.trace(err);
return;
}
console.log('session started:', result)
});
disconnect()
Closes session and disconnects from zello server. To start session again you need to call
session.connect
- Source:
sendImage(options) → {ZCC.OutgoingImage}
Starts sending an image message by creating OutgoingImage instance
Parameters:
Name | Type | Description |
---|---|---|
options |
object | options for outgoing image. |
Properties:
Name | Type | Description |
---|---|---|
for |
String | optional username to send this image to |
preview |
Boolean | set it to false to automatically send an image without previewing. if set to true (default) you will need to call OutgoingImage.send() to send an image |
File |
File | object (optional) if provided this file is send as an image with a source 'library' |
- Source:
Returns:
OutgoingImage object
- Type
- ZCC.OutgoingImage
Example
var outgoingImage = session.sendImage({
preview: false,
for: 'username'
});
sendTextMessage(options, userCallbackopt) → {promise}
Sends a text message
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
options |
object | options for outgoing text message. | ||
userCallback |
function |
<optional> |
null | callback that is fired on message being send or failed to be sent |
Properties:
Name | Type | Description |
---|---|---|
for |
String | optional username to send this text message to |
text |
String | message text |
- Source:
Returns:
promise that resolves once session successfully send a text message and rejects if
text message sending failed
- Type
- promise
Example
session.sendTextMessage({
for: 'username',
text: 'Hello Zello!'
});
startVoiceMessage(options) → {ZCC.OutgoingMessage}
Starts a voice message by creating OutgoingMessage instance
Parameters:
Name | Type | Description |
---|---|---|
options |
object | options for outgoing messages.
Options can also include recorder and encoder overrides. |
- Source:
Returns:
OutgoingMessage object
- Type
- ZCC.OutgoingMessage
Example
// use default recorder and encoder
var outgoingMessage = session.startVoiceMessage();
// use custom recorder
var outgoingMessage = session.startVoiceMessage({
recorder: CustomRecorder
});
// use custom recorder and encoder
var outgoingMessage = session.startVoiceMessage({
recorder: CustomRecorder,
encoder: CustomEncoder
});
Events
error
The Session received error message from server
Parameters:
Name | Type | Description |
---|---|---|
error |
string | Error description |
- Source:
incoming_image
Incoming image JSON metadata
Parameters:
Name | Type | Description |
---|---|---|
IncomingImage |
ZCC.IncomingImage | incoming image instance |
- Source:
incoming_location
Incoming location coordinates
Parameters:
Name | Type | Description |
---|---|---|
json |
location location data JSON |
- Source:
incoming_text_message
Incoming channel text message
Parameters:
Name | Type | Description |
---|---|---|
json |
textMessage textMessage JSON |
- Source:
incoming_voice_data
The Session is receiving incoming voice message packet (with encoded audio)
Parameters:
Name | Type | Description |
---|---|---|
incomingVoicePacket |
Object | voice message packet object |
Properties:
Name | Type | Description |
---|---|---|
messageData |
Uint8Array | encoded (opus) data |
messageId |
Number | incoming message id |
packetId |
Number | incoming packet id |
- Source:
incoming_voice_data_decoded
Incoming voice message packet decoded
Parameters:
Name | Type | Description |
---|---|---|
pcmData |
Float32Array | decoded pcm packet |
incoming |
ZCC.IncomingMessage | message instance |
- Source:
incoming_voice_did_start
Incoming voice message did start (first packet received)
Parameters:
Name | Type | Description |
---|---|---|
incoming |
ZCC.IncomingMessage | message instance |
- Source:
incoming_voice_did_stop
Incoming voice message stopped
Parameters:
Name | Type | Description |
---|---|---|
incomingMessage |
ZCC.IncomingMessage | incoming message instance |
- Source:
incoming_voice_will_start
Incoming voice message is about to start.
Parameters:
Name | Type | Description |
---|---|---|
incomingMessage |
ZCC.IncomingMessage | message instance |
- Source:
session_connect
The Session has connected and signed in successfully
- Source:
session_connection_lost
The Session was disconnected and will try to reconnect
Parameters:
Name | Type | Description |
---|---|---|
error |
string | Error description |
- Source:
session_disconnect
The Session was disconnected and failed to reconnect
Parameters:
Name | Type | Description |
---|---|---|
error |
string | Error description |
- Source:
session_fail_connect
The Session has failed to connect or sign in.
Parameters:
Name | Type | Description |
---|---|---|
error |
string | Error description |
- Source:
session_start_connect
The Session has opened a websocket connection to the server and ready to sign in
- Source:
status
The Session is receiving channel status update
Parameters:
Name | Type | Description |
---|---|---|
status |
JSON | JSON object |
Properties:
Name | Type | Description |
---|---|---|
channel |
String | channel name |
status |
String | new channel status |
users_online |
Number | number of online users |
- Source: