Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

twilio-sync

Package Overview
Dependencies
Maintainers
1
Versions
608
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

twilio-sync

Twilio Sync client library

  • 0.13.0
  • npm
  • Socket score

Version published
Weekly downloads
91K
decreased by-22.74%
Maintainers
1
Weekly downloads
 
Created
Source

Twilio Sync JavaScript client library

Twilio Sync is Twilio's state synchronization service, offering two-way real-time communication between browsers, mobiles, and the cloud. Visit our official site for more details: https://www.twilio.com/sync

Installation

NPM

npm install --save twilio-sync

Using this method, you can require twilio-sync.js like so:

var SyncClient = require('twilio-sync');
var syncClient = new SyncClient(token);

CDN

Releases of twilio-sync.js are hosted on a CDN, and you can include these directly in your web app using a <script> tag.

<script type="text/javascript" src="//media.twiliocdn.com/sdk/js/sync/v0.12/twilio-sync.min.js"></script>

Using this method, twilio-sync.js will set a browser global:

var syncClient = new Twilio.Sync.Client(token);

Usage

To use the library, you need to generate an Access Token and pass it to the Sync Client constructor. The Twilio SDK Starter applications for Node.js, Java, PHP, Ruby, Python, C# provide an easy way to set up a token generator locally. Alternatively, you can set up a Twilio Function based on the Sync Access Token template.

// Obtain a JWT access token: https://www.twilio.com/docs/sync/identity-and-access-tokens
var token = '<your-access-token-here>';
var syncClient = new Twilio.Sync.Client(token);

// Open a Document by unique name and update its value
syncClient.document('MyDocument')
  .then(function(document) {
    // Listen to updates on the Document
    document.on('updated', function(event) {
      console.log('Received Document update event. New value:', event.value);
    });

    // Update the Document value
    var newValue = { temperature: 23 };
    return document.set(newValue);
  })
  .then(function(updateResult) {
    console.log('The Document was successfully updated', updateResult)
  })
  .catch(function(error) {
    console.error('Unexpected error', error)
  });

For more code examples for Documents and other Sync objects, refer to the SDK API Docs:

Changelog

See this link.

FAQs

Package last updated on 09 Dec 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc