Constructor
new Tinode(config, onComplete)
Create Tinode object.
Parameters:
Name | Type | Description | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
config |
Object
|
configuration parameters.
|
||||||||||||||||||||||||
onComplete |
function
|
callback to call when initialization is completed. |
Members
onAutoreconnectIteration :onAutoreconnectIteration
Callback to be notified when exponential backoff is iterating.
Type:
-
onAutoreconnectIteration
onConnect :onConnect
Callback to report when connection with Tinode server is established.
Type:
-
onConnect
onCtrlMessage :onCtrlMessage
Callback to receive
{ctrl}
(control) messages.
Type:
-
onCtrlMessage
onDataMessage :onDataMessage
Callback to recieve
{data}
(content) messages.
Type:
-
onDataMessage
onDisconnect :onDisconnect
Callback to report when connection is lost. The callback has no parameters.
Type:
-
onDisconnect
onMessage :onMessage
Callback to receive all messages as objects.
Type:
-
onMessage
onNetworkProbe :onNetworkProbe
Callback to receive server responses to network probes. See Tinode#networkProbe
Type:
-
onNetworkProbe
onPresMessage :onPresMessage
Callback to receive
{pres}
(presence) messages.
Type:
-
onPresMessage
onRawMessage :onRawMessage
Callback to receive all messages as unparsed text.
Type:
-
onRawMessage
onWebsocketOpen :onWebsocketOpen
Callback to report when the websocket is opened. The callback has no parameters.
Type:
-
onWebsocketOpen
Methods
(static) credential(meth, valopt, paramsopt, respopt) → {Array.<Credential>}
Helper method to package account credential.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
meth |
string
|
Credential
|
validation method or object with validation data. | |
val |
string
|
<optional> |
validation value (e.g. email or phone number). |
params |
Object
|
<optional> |
validation parameters. |
resp |
string
|
<optional> |
validation response. |
Returns:
- Type:
-
Array.<Credential>
array with a single credential or
null
if no valid credentials were given.
(static) getLibrary() → {string}
Return information about the current name and version of this Tinode library.
Returns:
- Type:
-
string
the name of the library and it's version.
(static) getVersion() → {string}
Get information about the current version of this Tinode client library.
Returns:
- Type:
-
string
semantic version of the library, e.g.
"0.15.5-rc1"
.
(static) isChannelTopicName(name) → {boolean}
Check if the topic name is a name of a channel.
Parameters:
Name | Type | Description |
---|---|---|
name |
string
|
topic name to check. |
Returns:
- Type:
-
boolean
true
if the name is a name of a channel, false
otherwise.
(static) isCommTopicName(name) → {boolean}
Check if the given topic name is a name of a communication topic, i.e. P2P or group.
Parameters:
Name | Type | Description |
---|---|---|
name |
string
|
Name of the topic to test. |
Returns:
- Type:
-
boolean
true
if the name is a name of a p2p or group topic, false
otherwise.
(static) isGroupTopicName(name) → {boolean}
Check if the given topic name is a name of a group topic.
Parameters:
Name | Type | Description |
---|---|---|
name |
string
|
Name of the topic to test. |
Returns:
- Type:
-
boolean
true
if the name is a name of a group topic, false
otherwise.
(static) isMeTopicName(name) → {boolean}
Check if the given topic name is a name of a 'me' topic.
Parameters:
Name | Type | Description |
---|---|---|
name |
string
|
Name of the topic to test. |
Returns:
- Type:
-
boolean
true
if the name is a name of a 'me' topic, false
otherwise.
(static) isNewGroupTopicName(name) → {boolean}
Check if the topic name is a name of a new topic.
Parameters:
Name | Type | Description |
---|---|---|
name |
string
|
topic name to check. |
Returns:
- Type:
-
boolean
true
if the name is a name of a new topic, false
otherwise.
(static) isNullValue(str) → {boolean}
Check if the given string represents
NULL
value as defined by Tinode ('\u2421'
).
Parameters:
Name | Type | Description |
---|---|---|
str |
string
|
string to check for NULL value.
|
Returns:
- Type:
-
boolean
true
if string represents NULL
value, false
otherwise.
(static) isP2PTopicName(name) → {boolean}
Check if the given topic name is a name of a p2p topic.
Parameters:
Name | Type | Description |
---|---|---|
name |
string
|
Name of the topic to test. |
Returns:
- Type:
-
boolean
true
if the name is a name of a p2p topic, false
otherwise.
(static) setDatabaseProvider(idbProvider)
To use Tinode in a non browser context, supply
indexedDB
provider.
Parameters:
Name | Type | Description |
---|---|---|
idbProvider |
indexedDB provider, e.g. for nodeJS , require('fake-indexeddb') .
|
(static) setNetworkProviders(wsProvider, xhrProvider)
To use Tinode in a non browser context, supply WebSocket and XMLHttpRequest providers.
Parameters:
Name | Type | Description |
---|---|---|
wsProvider |
WebSocket provider, e.g. for nodeJS , require('ws') .
|
|
xhrProvider |
XMLHttpRequest provider, e.g. for node require('xhr') .
|
(static) topicType(name) → {string}
Determine topic type from topic's name: grp, p2p, me, fnd, sys.
Parameters:
Name | Type | Description |
---|---|---|
name |
string
|
Name of the topic to test. |
Returns:
- Type:
-
string
One of
"me"
, "fnd"
, "sys"
, "grp"
,
"p2p"
or undefined
.
account(uid, scheme, secret, loginopt, paramsopt) → {Promise}
Create or update an account.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
uid |
string
|
User id to update | |
scheme |
string
|
Authentication scheme; "basic" and "anonymous" are the currently supported schemes.
|
|
secret |
string
|
Authentication secret, assumed to be already base64 encoded. | |
login |
boolean
|
<optional> |
Use new account to authenticate current session |
params |
AccountParams
|
<optional> |
User data to pass to the server. |
Returns:
- Type:
-
Promise
Promise which will be resolved/rejected when server reply is received.
authorizeURL(URL) → {string}
Add API key and auth token to the relative URL making it usable for getting data
from the server in a simple
HTTP GET
request.
Parameters:
Name | Type | Description |
---|---|---|
URL |
string
|
URL to wrap. |
Returns:
- Type:
-
string
URL with appended API key and token, if valid token is present.
cacheGetTopic(topicName) → {Topic}
Get a named topic from cache.
Parameters:
Name | Type | Description |
---|---|---|
topicName |
string
|
Name of the topic to get. |
cacheRemTopic(topicName)
Remove named topic from cache.
Parameters:
Name | Type | Description |
---|---|---|
topicName |
string
|
Name of the topic to remove from cache. |
clearStorage() → {Promise}
Clear persistent cache: remove IndexedDB.
Returns:
- Type:
-
Promise
Promise resolved/rejected when the operation is completed.
connect(host_) → {Promise}
Connect to the server.
Parameters:
Name | Type | Description |
---|---|---|
host_ |
string
|
name of the host to connect to. |
Returns:
- Type:
-
Promise
Promise resolved/rejected when the connection call completes:
resolve()
is called without parameters, reject()
receives the
Error
as a single parameter.
createAccount(scheme, secret, loginopt, paramsopt) → {Promise}
Create a new user. Wrapper for Tinode#account.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
scheme |
string
|
Authentication scheme; "basic" is the only currently supported scheme.
|
|
secret |
string
|
Authentication. | |
login |
boolean
|
<optional> |
Use new account to authenticate current session |
params |
AccountParams
|
<optional> |
User data to pass to the server. |
Returns:
- Type:
-
Promise
Promise which will be resolved/rejected when server reply is received.
createAccountBasic(username, password, paramsopt) → {Promise}
Create user with
'basic'
authentication scheme and immediately
use it for authentication. Wrapper for Tinode#account.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
username |
string
|
Login to use for the new account. | |
password |
string
|
User's password. | |
params |
AccountParams
|
<optional> |
User data to pass to the server. |
Returns:
- Type:
-
Promise
Promise which will be resolved/rejected when server reply is received.
createMessage(topic, content, noEchoopt) → {Object}
Create message draft without sending it to the server.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
topic |
string
|
Name of the topic to publish to. | |
content |
Object
|
Payload to publish. | |
noEcho |
boolean
|
<optional> |
If true , tell the server not to echo the message to the original session.
|
Returns:
- Type:
-
Object
new message which can be sent to the server or otherwise used.
delCredential(method, value) → {Promise}
Delete credential. Always sent on
'me'
topic.
Parameters:
Name | Type | Description |
---|---|---|
method |
string
|
validation method such as 'email' or 'tel' .
|
value |
string
|
validation value, i.e. 'alice@example.com' .
|
Returns:
- Type:
-
Promise
Promise which will be resolved/rejected on receiving server reply.
delCurrentUser(hard) → {Promise}
Request to delete account of the current user.
Parameters:
Name | Type | Description |
---|---|---|
hard |
boolean
|
hard-delete user. |
Returns:
- Type:
-
Promise
Promise which will be resolved/rejected on receiving server reply.
delMessages(topic, list, hardopt) → {Promise}
Delete some or all messages in a topic.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
topic |
string
|
Topic name to delete messages from. | |
list |
Array.<DelRange>
|
Ranges of message IDs to delete. | |
hard |
boolean
|
<optional> |
Hard or soft delete |
Returns:
- Type:
-
Promise
Promise which will be resolved/rejected on receiving server reply.
delSubscription(topicName, user) → {Promise}
Delete subscription. Requires Share permission.
Parameters:
Name | Type | Description |
---|---|---|
topicName |
string
|
Name of the topic to delete |
user |
string
|
User ID to remove. |
Returns:
- Type:
-
Promise
Promise which will be resolved/rejected on receiving server reply.
delTopic(topicName, hard) → {Promise}
Delete the topic alltogether. Requires Owner permission.
Parameters:
Name | Type | Description |
---|---|---|
topicName |
string
|
Name of the topic to delete |
hard |
boolean
|
hard-delete topic. |
Returns:
- Type:
-
Promise
Promise which will be resolved/rejected on receiving server reply.
enableLogging(enabled, trimLongStrings)
Toggle console logging. Logging is off by default.
Parameters:
Name | Type | Description |
---|---|---|
enabled |
boolean
|
Set to true to enable logging to console.
|
trimLongStrings |
boolean
|
Set to true to trim long strings.
|
getAuthToken() → {AuthToken}
Get stored authentication token.
Returns:
- Type:
-
AuthToken
authentication token.
getCurrentLogin() → {string}
Get login used for last successful authentication.
Returns:
- Type:
-
string
login last used successfully or
undefined
.
getCurrentUserID() → {string}
Get the UID of the the current authenticated user.
Returns:
- Type:
-
string
UID of the current user or
undefined
if the session is not yet
authenticated or if there is no session.
getFndTopic() → {Topic}
Instantiate
'fnd'
(find) topic or get it from cache.
getLargeFileHelper() → {LargeFileHelper}
Create a new LargeFileHelper instance
getMeta(topic, params) → {Promise}
Request topic metadata
Parameters:
Name | Type | Description |
---|---|---|
topic |
string
|
Name of the topic to query. |
params |
GetQuery
|
Parameters of the query. Use Tinode.MetaGetBuilder to generate. |
Returns:
- Type:
-
Promise
Promise which will be resolved/rejected on receiving server reply.
getMeTopic() → {TopicMe}
Instantiate
'me'
topic or get it from cache.
Returns:
- Type:
-
TopicMe
Instance of
'me'
topic.
getServerInfo() → {Object}
Return information about the server: protocol version and build timestamp.
Returns:
- Type:
-
Object
build and version of the server or
null
if there is no connection or
if the first server response has not been received yet.
getServerParam(name, defaultValue) → {Object}
Return server-provided configuration value.
Parameters:
Name | Type | Description |
---|---|---|
name |
string
|
of the value to return. |
defaultValue |
Object
|
to return in case the parameter is not set or not found. |
Returns:
- Type:
-
Object
named value.
getTopic(topicName) → {Topic}
Get a named topic, either pull it from cache or create a new instance.
There is a single instance of topic for each name.
Parameters:
Name | Type | Description |
---|---|---|
topicName |
string
|
Name of the topic to get. |
getTopicAccessMode(name) → {AccessMode}
Get access mode for the given contact.
Parameters:
Name | Type | Description |
---|---|---|
name |
string
|
of the topic to query. |
Returns:
- Type:
-
AccessMode
access mode if topic is found, null otherwise.
hello() → {Promise}
Send handshake to the server.
Returns:
- Type:
-
Promise
Promise which will be resolved/rejected when server reply is received.
initStorage() → {Promise}
Initialize persistent cache: create IndexedDB cache.
Returns:
- Type:
-
Promise
Promise resolved/rejected when the operation is completed.
isAuthenticated() → {boolean}
Check if connection is authenticated (last login was successful).
Returns:
- Type:
-
boolean
true
if authenticated, false
otherwise.
isConnected() → {boolean}
Check for live connection to server.
Returns:
- Type:
-
boolean
true
if there is a live connection, false
otherwise.
isMe(uid) → {boolean}
Check if the given user ID is equal to the current user's UID.
Parameters:
Name | Type | Description |
---|---|---|
uid |
string
|
UID to check. |
Returns:
- Type:
-
boolean
true if the given UID belongs to the current logged in user.
isTopicCached(topicName) → {boolean}
Check if named topic is already present in cache.
Parameters:
Name | Type | Description |
---|---|---|
topicName |
string
|
Name of the topic to check. |
Returns:
- Type:
-
boolean
true if topic is found in cache, false otherwise.
isTopicOnline(name) → {boolean}
Check if given topic is online.
Parameters:
Name | Type | Description |
---|---|---|
name |
string
|
of the topic to test. |
Returns:
- Type:
-
boolean
true if topic is online, false otherwise.
leave(topic, unsub) → {Promise}
Detach and optionally unsubscribe from the topic
Parameters:
Name | Type | Description |
---|---|---|
topic |
string
|
Topic to detach from. |
unsub |
boolean
|
If true , detach and unsubscribe, otherwise just detach.
|
Returns:
- Type:
-
Promise
Promise which will be resolved/rejected on receiving server reply.
login(scheme, secret, credopt) → {Promise}
Authenticate current session.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
scheme |
string
|
Authentication scheme; "basic" is the only currently supported scheme.
|
|
secret |
string
|
Authentication secret, assumed to be already base64 encoded. | |
cred |
Credential
|
<optional> |
credential confirmation, if required. |
Returns:
- Type:
-
Promise
Promise which will be resolved/rejected when server reply is received.
loginBasic(uname, password, credopt) → {Promise}
Wrapper for Tinode#login with basic authentication
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
uname |
string
|
User name. | |
password |
string
|
Password. | |
cred |
Credential
|
<optional> |
credential confirmation, if required. |
Returns:
- Type:
-
Promise
Promise which will be resolved/rejected on receiving server reply.
loginToken(token, credopt) → {Promise}
Wrapper for Tinode#login with token authentication
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
token |
string
|
Token received in response to earlier login. | |
cred |
Credential
|
<optional> |
credential confirmation, if required. |
Returns:
- Type:
-
Promise
Promise which will be resolved/rejected on receiving server reply.
mapTopics(func, context)
Iterate over cached topics.
Parameters:
Name | Type | Description |
---|---|---|
func |
function
|
callback to call for each topic. |
context |
Object
|
'this' inside the 'func'. |
networkProbe()
Send a network probe message to make sure the connection is alive.
newGroupTopicName(isChan) → {string}
Generate unique name like
'new123456'
suitable for creating a new group topic.
Parameters:
Name | Type | Description |
---|---|---|
isChan |
boolean
|
if the topic is channel-enabled. |
Returns:
- Type:
-
string
name which can be used for creating a new group topic.
note(topicName, what, seq)
Notify server that a message or messages were read or received. Does NOT return promise.
Parameters:
Name | Type | Description |
---|---|---|
topicName |
string
|
Name of the topic where the mesage is being aknowledged. |
what |
string
|
Action being aknowledged, either "read" or "recv" .
|
seq |
number
|
Maximum id of the message being acknowledged. |
noteKeyPress(topicName, typeopt)
Broadcast a key-press notification to topic subscribers. Used to show
typing notifications "user X is typing...".
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
topicName |
string
|
Name of the topic to broadcast to. | |
type |
string
|
<optional> |
notification to send, default is 'kp'. |
oobNotification(data)
Out of band notification: notify topic that an external (push) notification was recived by the client.
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data |
object
|
notification payload.
|
publish(topicName, content, noEchoopt) → {Promise}
Publish {data} message to topic.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
topicName |
string
|
Name of the topic to publish to. | |
content |
Object
|
Payload to publish. | |
noEcho |
boolean
|
<optional> |
If true , tell the server not to echo the message to the original session.
|
Returns:
- Type:
-
Promise
Promise which will be resolved/rejected on receiving server reply.
publishMessage(pub, attachmentsopt) → {Promise}
Publish message to topic. The message should be created by Tinode#createMessage.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pub |
Object
|
Message to publish. | |
attachments |
Array.<string>
|
<optional> |
array of URLs with attachments. |
Returns:
- Type:
-
Promise
Promise which will be resolved/rejected on receiving server reply.
reconnect(force)
Attempt to reconnect to the server immediately.
Parameters:
Name | Type | Description |
---|---|---|
force |
string
|
if true , reconnect even if there is a connection already.
|
report(action, target) → {Promise}
Report a topic for abuse. Wrapper for Tinode#publish.
Parameters:
Name | Type | Description |
---|---|---|
action |
string
|
the only supported action is 'report'. |
target |
string
|
name of the topic being reported. |
Returns:
- Type:
-
Promise
Promise to be resolved/rejected when the server responds to request.
requestResetAuthSecret(scheme, method, value) → {Promise}
Send a request for resetting an authentication secret.
Parameters:
Name | Type | Description |
---|---|---|
scheme |
string
|
authentication scheme to reset. |
method |
string
|
method to use for resetting the secret, such as "email" or "tel". |
value |
string
|
value of the credential to use, a specific email address or a phone number. |
Returns:
- Type:
-
Promise
Promise which will be resolved/rejected on receiving the server reply.
setAuthToken(token)
Application may provide a saved authentication token.
Parameters:
Name | Type | Description |
---|---|---|
token |
AuthToken
|
authentication token. |
setDeviceToken(dt)
Set or refresh the push notifications/device token. If the client is connected,
the deviceToken can be sent to the server.
Parameters:
Name | Type | Description |
---|---|---|
dt |
string
|
token obtained from the provider or false ,
null or undefined to clear the token.
|
Returns:
true
if attempt was made to send the update to the server.
setHumanLanguage(hl)
Set UI language to report to the server. Must be called before
'hi'
is sent, otherwise it will not be used.
Parameters:
Name | Type | Description |
---|---|---|
hl |
string
|
human (UI) language, like "en_US" or "zh-Hans" .
|
setMeta(topic, params) → {Promise}
Update topic's metadata: description, subscribtions.
Parameters:
Name | Type | Description |
---|---|---|
topic |
string
|
Topic to update. |
params |
SetParams
|
topic metadata to update. |
Returns:
- Type:
-
Promise
Promise which will be resolved/rejected on receiving server reply.
subscribe(topic, getParamsopt, setParamsopt) → {Promise}
Send a topic subscription request.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
topic |
string
|
Name of the topic to subscribe to. | |
getParams |
GetQuery
|
<optional> |
Optional subscription metadata query |
setParams |
SetParams
|
<optional> |
Optional initialization parameters |
Returns:
- Type:
-
Promise
Promise which will be resolved/rejected on receiving server reply.
updateAccountBasic(uid, username, password, paramsopt) → {Promise}
Update user's credentials for
'basic'
authentication scheme. Wrapper for Tinode#account.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
uid |
string
|
User ID to update. | |
username |
string
|
Login to use for the new account. | |
password |
string
|
User's password. | |
params |
AccountParams
|
<optional> |
data to pass to the server. |
Returns:
- Type:
-
Promise
Promise which will be resolved/rejected when server reply is received.
videoCall(topicName, seq, evt, payload) → {Promise}
Send a video call notification to topic subscribers (including dialing,
hangup, etc.).
Parameters:
Name | Type | Description |
---|---|---|
topicName |
string
|
Name of the topic to broadcast to. |
seq |
int
|
ID of the call message the event pertains to. |
evt |
string
|
Call event. |
payload |
string
|
Payload associated with this event (e.g. SDP string). |
Returns:
- Type:
-
Promise
Promise (for some call events) which will
be resolved/rejected on receiving server reply