npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

twilio-sync

v3.3.5

Published

Twilio Sync client library

Downloads

388,124

Readme

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

via NPM

npm install --save twilio-sync

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

const { SyncClient } = require('twilio-sync');
const syncClient = new SyncClient(token);

via 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="//sdk.twilio.com/js/sync/v3.2/twilio-sync.min.js"></script>

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

const 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
const token = '<your-access-token-here>';
const syncClient = new Twilio.Sync.Client(token);

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

    // Update the Document data
    const newData = { temperature: 23 };
    return document.set(newData);
  })
  .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.