Tinode

tinode-sdk. Tinode

The main class for interacting with Tinode server.

Constructor

new Tinode(config, onComplete)

Create Tinode object.
Source:
Parameters:
Name Type Description
config Object configuration parameters.
Name Type Description
appName string Name of the calling application to be reported in the User Agent.
host string Host name and optional port number to connect to.
apiKey string API key generated by keygen.
transport string See Tinode.Connection#transport.
secure boolean Use Secure WebSocket if true.
platform string Optional platform identifier, one of "ios", "web", "android".
persist boolen Use IndexedDB persistent storage.
onComplete function callback to call when initialization is completed.

Members

onAutoreconnectIteration :onAutoreconnectIteration

Callback to be notified when exponential backoff is iterating.
Source:
Type:
  • onAutoreconnectIteration

onConnect :onConnect

Callback to report when connection with Tinode server is established.
Source:
Type:
  • onConnect

onCtrlMessage :onCtrlMessage

Callback to receive {ctrl} (control) messages.
Source:
Type:
  • onCtrlMessage

onDataMessage :onDataMessage

Callback to recieve {data} (content) messages.
Source:
Type:
  • onDataMessage

onDisconnect :onDisconnect

Callback to report when connection is lost. The callback has no parameters.
Source:
Type:
  • onDisconnect

onLogin :onLogin

Callback to report login completion.
Source:
Type:
  • onLogin

onMessage :onMessage

Callback to receive all messages as objects.
Source:
Type:
  • onMessage

onNetworkProbe :onNetworkProbe

Callback to receive server responses to network probes. See Tinode#networkProbe
Source:
Type:
  • onNetworkProbe

onPresMessage :onPresMessage

Callback to receive {pres} (presence) messages.
Source:
Type:
  • onPresMessage

onRawMessage :onRawMessage

Callback to receive all messages as unparsed text.
Source:
Type:
  • onRawMessage

onWebsocketOpen :onWebsocketOpen

Callback to report when the websocket is opened. The callback has no parameters.
Source:
Type:
  • onWebsocketOpen

Methods

(static) credential(meth, valopt, paramsopt, respopt) → {Array.<Credential>}

Helper method to package account credential.
Source:
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.
Source:
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.
Source:
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.
Source:
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.
Source:
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.
Source:
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.
Source:
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.
Source:
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').
Source:
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.
Source:
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.
Source:
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.
Source:
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.
Source:
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.
Source:
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.
Source:
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.
Source:
Parameters:
Name Type Description
topicName string Name of the topic to get.
Returns:
Type:
Topic
Requested topic or undefined if topic is not found in cache.

cacheRemTopic(topicName)

Remove named topic from cache.
Source:
Parameters:
Name Type Description
topicName string Name of the topic to remove from cache.

clearStorage() → {Promise}

Clear persistent cache: remove IndexedDB.
Source:
Returns:
Type:
Promise
Promise resolved/rejected when the operation is completed.

connect(host_) → {Promise}

Connect to the server.
Source:
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.
Source:
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.
Source:
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.
Source:
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.
Source:
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.
Source:
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.
Source:
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.
Source:
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.
Source:
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.

disconnect()

Disconnect from the server.
Source:

enableLogging(enabled, trimLongStrings)

Toggle console logging. Logging is off by default.
Source:
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.
Source:
Returns:
Type:
AuthToken
authentication token.

getCurrentLogin() → {string}

Get login used for last successful authentication.
Source:
Returns:
Type:
string
login last used successfully or undefined.

getCurrentUserID() → {string}

Get the UID of the the current authenticated user.
Source:
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.
Source:
Returns:
Type:
Topic
Instance of 'fnd' topic.

getLargeFileHelper() → {LargeFileHelper}

Create a new LargeFileHelper instance
Source:
Returns:
Type:
LargeFileHelper
instance of a Tinode.LargeFileHelper.

getMeta(topic, params) → {Promise}

Request topic metadata
Source:
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.
Source:
Returns:
Type:
TopicMe
Instance of 'me' topic.

getServerInfo() → {Object}

Return information about the server: protocol version and build timestamp.
Source:
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.
Source:
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.
Source:
Parameters:
Name Type Description
topicName string Name of the topic to get.
Returns:
Type:
Topic
Requested or newly created topic or undefined if topic name is invalid.

getTopicAccessMode(name) → {AccessMode}

Get access mode for the given contact.
Source:
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.
Source:
Returns:
Type:
Promise
Promise which will be resolved/rejected when server reply is received.

initStorage() → {Promise}

Initialize persistent cache: create IndexedDB cache.
Source:
Returns:
Type:
Promise
Promise resolved/rejected when the operation is completed.

isAuthenticated() → {boolean}

Check if connection is authenticated (last login was successful).
Source:
Returns:
Type:
boolean
true if authenticated, false otherwise.

isConnected() → {boolean}

Check for live connection to server.
Source:
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.
Source:
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.
Source:
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.
Source:
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
Source:
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.
Source:
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
Source:
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
Source:
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.
Source:
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.
Source:

newGroupTopicName(isChan) → {string}

Generate unique name like 'new123456' suitable for creating a new group topic.
Source:
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.
Source:
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...".
Source:
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.
Source:
Parameters:
Name Type Description
data object notification payload.
Name Type Attributes Description
what string notification type, 'msg', 'read', 'sub'.
topic string name of the updated topic.
seq number <optional>
seq ID of the affected message.
xfrom string <optional>
UID of the sender.
given object <optional>
new subscription 'given', e.g. 'ASWP...'.
want object <optional>
new subscription 'want', e.g. 'RWJ...'.

publish(topicName, content, noEchoopt) → {Promise}

Publish {data} message to topic.
Source:
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.
Source:
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.
Source:
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.
Source:
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.
Source:
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.
Source:
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.
Source:
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.
Source:
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.
Source:
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.
Source:
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.
Source:
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.).
Source:
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

wantAkn(status)

Include message ID into all subsequest messages to server instructin it to send aknowledgemens. Required for promises to function. Default is "on".
Deprecated:
  • Yes
Source:
Parameters:
Name Type Description
status boolean Turn aknowledgemens on or off.