Class: Sync
The Sync Class allows you to create Rich and Dynamic Experiences in your websites and applications using Live Data from Twilio Sync
Throughout this page, you will see
syncClient
with a lowercase "s" andSync
with an uppercase "S".
Sync
refers to theSync
object provided by the SDK.
syncClient
represents an instance of aSync
, created with thenew
keyword:
Instantiate a Sync Client
A new instance of Sync
should be constructed by using the new keyword and passing the Config payload as the first argument.
No signaling channel will be opened when instantiating a new Sync
Client. The signaling WebSocket will be opened when a syncClient.registerDocument()
syncClient.registerMap()
is called.
The maximum number of characters for the identity provided in the Access Token is 121. The identity may only contain alpha-numeric and underscore characters. Other characters, including spaces, or exceeding the maximum number of characters, will result in not being able to place or receive calls.
If a KioskId is provided when the
syncClient
is Created then the Kiosk Document for that KioskId is automatically Registered.
Initiate a Basic Sync Client
const syncClient = new Sync({
accountSid: "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
identity: "FIXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
});
To see all of the possible properties, see the Config interface section.
Hierarchy
EventEmitter
↳
Sync
Accessors
client
• get
client(): Client
Returns the underlaying Twilio SDK Client
for advanced configuration and usage
console.info(syncClient.client.connectionState);
Returns
Client
isSupported
• get
isSupported(): boolean
Returns if Sync is Supported in the current Browser / Context
console.info(syncClient.isSupported)
Returns
boolean
ready
• get
ready(): boolean
Is the syncClient
ready?
syncClient.ready ? console.info("Ready") ? console.info("Not Ready")
Returns
boolean
Methods
disconnect
▸ disconnect(): Promise
<void
>
Disconnect Sync Client
syncClient.disconnect();
Returns
Promise
<void
>
document
▸ document(name
): SyncDocument
Returns the Specified "Document"
console.info(syncClient.document["myDocument"].lastEventId)
Parameters
Name | Type |
---|---|
name | string |
Returns
SyncDocument
init
▸ init(): Promise
<void
>
Init the Sync Client
Should only be used if the
Client
is destroyed and a "re-init" is required for some bizare reason
await syncClient.init();
Returns
Promise
<void
>
map
▸ map(name
): SyncMap
Returns the Specified "Map"
console.info(syncClient.map["myMap"].lastEventId)
Parameters
Name | Type |
---|---|
name | string |
Returns
SyncMap
registerDocument
▸ registerDocument(Payload
): Promise
<SyncDocument
>
Register a Sync Document
const document = syncClient.registerDocument({ name: "myDocument" });
Parameters
Name | Type |
---|---|
Payload | RegisterDocumentPayload |
Returns
Promise
<SyncDocument
>
registerMap
▸ registerMap(Payload
): Promise
<SyncMap
>
Register a Sync Map
const map = syncClient.registerMap({ name: "myMap" });
Parameters
Name | Type |
---|---|
Payload | RegisterMapPayload |
Returns
Promise
<SyncMap
>
updateToken
▸ updateToken(newToken
): void
Manually update Race Authentication Token
syncClient.on("sync#tokenAboutToExpire", () => {
// Get New Token
syncClient.updateToken(newToken);
});
Parameters
Name | Type |
---|---|
newToken | string |
Returns
void