Tinode

Tinode

new Tinode(appname_, host_, apiKey_, transport_, secure_, platform_)

Source:
Parameters:
Name Type Description
appname_ string Name of the caliing application to be reported in User Agent.
host_ string Host name and 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".

Classes

AccessMode
AccessMode
CBuffer
Connection
LargeFileHelper
Message
MetaGetBuilder
Topic
TopicFnd
TopicMe

Members

onAutoreconnectIteration :Tinode.onAutoreconnectIteration

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

onConnect :Tinode.onConnect

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

onCtrlMessage :Tinode.onCtrlMessage

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

onDataMessage :Tinode.onDataMessage

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

onDisconnect :Tinode.onDisconnect

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

onLogin :Tinode.onLogin

Callback to report login completion.
Source:
Type:

onMessage :Tinode.onMessage

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

onNetworkProbe :Tinode.onNetworkProbe

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

onPresMessage :Tinode.onPresMessage

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

onRawMessage :Tinode.onRawMessage

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

onWebsocketOpen :Tinode.onWebsocketOpen

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

Methods

(static) credential(meth, valopt, paramsopt, respopt) → {Array}

Helper method to package account credential.
Source:
Parameters:
Name Type Attributes Description
meth String | Object 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
array with a single credentail 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}

Return 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.

(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) 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.

(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) isRelativeURL(url) → {boolean}

Check if the given URL string is a relative URL. Check for cases like: 'http://example.com' ' http://example.com' '//example.com/' 'http:example.com' 'http:/example.com'
Source:
Parameters:
Name Type Description
url String URL string to check.
Returns:
Type:
boolean
true if the URL is relative, false otherwise.

(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.
Source:
Parameters:
Name Type Description
name string Name of the topic to test.
Returns:
Type:
string
One of 'me', 'grp', 'p2p' or undefined.

account(uid, scheme, secret, loginopt, paramsopt)

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 Tinode.AccountParams <optional>
User data to pass to the server.

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 GET request.
Source:
Parameters:
Name Type Description
URL String to wrap.
Returns:
Type:
string
URL with appended API key and token, if valid token is present.

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 Tinode.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 Tinode.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, data, 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.
data 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.<Tinode.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(topic, user) → {Promise}

Delete subscription. Requires Share permission.
Source:
Parameters:
Name Type Description
topic 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(topic, hard) → {Promise}

Delete the topic alltogether. Requires Owner permission.
Source:
Parameters:
Name Type Description
topic 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() → {Tinode.AuthToken}

Get stored authentication token.
Source:
Returns:
Type:
Tinode.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() → {Tinode.Topic}

Instantiate 'fnd' (find) topic or get it from cache.
Source:
Returns:
Type:
Tinode.Topic
Instance of 'fnd' topic.

getLargeFileHelper() → {Tinode.LargeFileHelper}

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

getMeta(topic, params) → {Promise}

Request topic metadata
Source:
Parameters:
Name Type Description
topic String Name of the topic to query.
params Tinode.GetQuery Parameters of the query. Use {Tinode.MetaGetBuilder} to generate.
Returns:
Type:
Promise
Promise which will be resolved/rejected on receiving server reply.

getMeTopic() → {Tinode.TopicMe}

Instantiate 'me' topic or get it from cache.
Source:
Returns:
Type:
Tinode.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.

getServerLimit(name, defaultValue) → {integer}

Return server-provided configuration value (long integer).
Source:
Parameters:
Name Type Description
name String of the value to return
defaultValue Object to return in case server limit is not set or not found.
Returns:
Type:
integer
named value.

getTopic(name) → {Tinode.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
name String Name of the topic to get.
Returns:
Type:
Tinode.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.

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(name) → {Boolean}

Check if named topic is already present in cache.
Source:
Parameters:
Name Type Description
name String Name of the topic to check.
Returns:
Type:
Boolean
true if topic is found in cache, false oterwise.

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) → {Promise}

Authenticate current session.
Source:
Parameters:
Name Type Description
scheme String Authentication scheme; "basic" is the only currently supported scheme.
secret String Authentication secret, assumed to be already base64 encoded.
Returns:
Type:
Promise
Promise which will be resolved/rejected when server reply is received.

loginBasic(uname, password) → {Promise}

Wrapper for Tinode#login with basic authentication
Source:
Parameters:
Name Type Description
uname String User name.
password String Password.
Returns:
Type:
Promise
Promise which will be resolved/rejected on receiving server reply.

loginToken(token) → {Promise}

Wrapper for Tinode#login with token authentication
Source:
Parameters:
Name Type Description
token String Token received in response to earlier login.
Returns:
Type:
Promise
Promise which will be resolved/rejected on receiving server reply.

networkProbe()

Send a network probe message to make sure the connection is alive.
Source:

newChannel(callbacks) → {Tinode.Topic}

Instantiate a new channel-enabled group topic. An actual name will be assigned by the server on Tinode.Topic.subscribe.
Source:
Parameters:
Name Type Description
callbacks Tinode.Callbacks Object with callbacks for various events.
Returns:
Type:
Tinode.Topic
Newly created topic.

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.

newTopic(callbacks) → {Tinode.Topic}

Instantiate a new group topic. An actual name will be assigned by the server on Tinode.Topic.subscribe.
Source:
Parameters:
Name Type Description
callbacks Tinode.Callbacks Object with callbacks for various events.
Returns:
Type:
Tinode.Topic
Newly created topic.

newTopicWith(peer, callbacks) → {Tinode.Topic}

Instantiate a new P2P topic with a given peer.
Source:
Parameters:
Name Type Description
peer string UID of the peer to start topic with.
callbacks Tinode.Callbacks Object with callbacks for various events.
Returns:
Type:
Tinode.Topic
Newly created topic.

note(topic, what, seq)

Notify server that a message or messages were read or received. Does NOT return promise.
Source:
Parameters:
Name Type Description
topic 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(topic)

Broadcast a key-press notification to topic subscribers. Used to show typing notifications "user X is typing...".
Source:
Parameters:
Name Type Description
topic String Name of the topic to broadcast to.

publish(topic, data, noEchoopt) → {Promise}

Publish {data} message to topic.
Source:
Parameters:
Name Type Attributes Description
topic String Name of the topic to publish to.
data 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) → {Promise}

Publish message to topic. The message should be created by Tinode#createMessage.
Source:
Parameters:
Name Type Description
pub Object Message to publish.
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 reconnect even if there is a connection already.

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 Tinode.AuthToken authentication token.

setDeviceToken(dt, sendToServer)

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.
sendToServer boolean if true, send dt to server immediately.
Returns:
true if attempt was made to send the token 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 Tinode.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 Tinode.GetQuery <optional>
Optional subscription metadata query
setParams Tinode.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 Tinode.AccountParams <optional>
data to pass to the server.
Returns:
Type:
Promise
Promise which will be resolved/rejected when server reply is received.

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.

Type Definitions

AccountParams

Properties:
Name Type Attributes Description
defacs Tinode.DefAcs <optional>
Default access parameters for user's me topic.
public Object <optional>
Public application-defined data exposed on me topic.
private Object <optional>
Private application-defined data accessible on me topic.
tags Array array of string tags for user discovery.
token string <optional>
authentication token to use.
Source:
Type:
  • Object

AuthToken

Properties:
Name Type Description
token String Token value.
expires Date Token expiration time.
Source:
Type:
  • Object

Credential

Properties:
Name Type Description
meth string validation method such as 'email' or 'tel'.
val string credential value, i.e. 'jdoe@example.com' or '+17025551234'
done boolean true if credential is validated.
Source:
Type:
  • Object

DefAcs

Properties:
Name Type Attributes Description
auth string <optional>
Access mode for me for authenticated users.
anon string <optional>
Access mode for me anonymous users.
Source:
Type:
  • Object

DelRange

Range of message IDs to delete.
Properties:
Name Type Attributes Description
low Number low end of the range, inclusive (closed).
hi Number <optional>
high end of the range, exclusive (open).
Source:
Type:
  • Object

GetDataType

Properties:
Name Type Attributes Description
since Number <optional>
Load messages with seq id equal or greater than this value.
before Number <optional>
Load messages with seq id lower than this number.
limit Number <optional>
Maximum number of results to return.
Source:
Type:
  • Object

GetOptsType

Properties:
Name Type Attributes Description
ims Date <optional>
"If modified since", fetch data only it was was modified since stated date.
limit Number <optional>
Maximum number of results to return. Ignored when querying topic description.
Source:
Type:
  • Object

GetQuery

Properties:
Name Type Attributes Description
desc Tinode.GetOptsType <optional>
If provided (even if empty), fetch topic description.
sub Tinode.GetOptsType <optional>
If provided (even if empty), fetch topic subscriptions.
data Tinode.GetDataType <optional>
If provided (even if empty), get messages.
Source:
Type:
  • Object

onConnect(code, text, params)

Source:
Parameters:
Name Type Description
code number Result code
text string Text epxplaining the completion, i.e "OK" or an error message.
params Tinode.ServerParams Parameters returned by the server.

onLogin(code, text)

Source:
Parameters:
Name Type Description
code number NUmeric completion code, same as HTTP status codes.
text string Explanation of the completion code.

ServerParams

Properties:
Name Type Attributes Description
ver string Server version
build string Server build
sid string <optional>
Session ID, long polling connections only.
Source:
Type:
  • Object

SetDesc

Properties:
Name Type Attributes Description
defacs Tinode.DefAcs <optional>
Default access mode.
public Object <optional>
Free-form topic description, publically accessible.
private Object <optional>
Free-form topic descriptionaccessible only to the owner.
Source:

SetParams

Properties:
Name Type Attributes Description
desc Tinode.SetDesc <optional>
Topic initialization parameters when creating a new topic or a new subscription.
sub Tinode.SetSub <optional>
Subscription initialization parameters.
Source:

SetSub

Properties:
Name Type Attributes Description
user String <optional>
UID of the user affected by the request. Default (empty) - current user.
mode String <optional>
User access mode, either requested or assigned dependent on context.
info Object <optional>
Free-form payload to pass to the invited user or topic manager.
Source:

SubscriptionParams

Parameters passed to Tinode#subscribe.
Properties:
Name Type Attributes Description
set Tinode.SetParams <optional>
Parameters used to initialize topic
get Tinode.GetQuery <optional>
Query for fetching data from topic.
Source: