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

bespoke-synchro

v3.0.1

Published

Synchronize slide changing across browser windows and networks

Downloads

25

Readme

bespoke-synchro

Presentation Synchronizing for Bespoke.js

This bespoke plugin synchronises the current slide index between multiple clients.

By default only slides accessed on localhost can broadcast a new slide index to other slides.

Installation

$ npm install bespoke-synchro

This module should be installed with npm, since it's packaged with a necessary WebSocket mediator server

Usage

On the client side (options shown are defaults):

var bespoke = require('bespoke'),
  synchro = require('bespoke-synchro');

bespoke.from('article', [
  synchro({
    port: 9999,
    url: 'ws://' + location.href
  })
]);

The bespoke-synchro plugin relies on a WebSocket mediator to interface between presentation instances (e.g. between each loaded presentation in a browser).

Enable/Disable

There may be certain circumstances where controlling the ability to sending and/or receive synchronization packets is desirable. The return value of synchro comes with disable, enable and toggle methods:

bespoke.from('article', [
  synchro = synchro({
    port: 9999,
    url: 'ws://' + location.href
  })
]);

document.addEventListener('keydown', function(e) {
  if (e.which === 's'.charCodeAt(0)) {
    synchro.toggle();
  }
});

Each of the methods (disable, enable and toggle) have rx (e.g. receive) and tx (e.g. transmit), submethods. Use these to control only one side of the interface

if (slave) {
  synchro.disable.tx();
}
if (master) {
  synchro.disable.rx();
}

Mediator

In node (options shown are defaults)

var mediator = require('bespoke-synchro/mediator')
mediator({port:9999, control: <internal function>});

The options supplied to mediator are passed directly to ws.Server, see https://github.com/websockets/ws/blob/master/doc/ws.md

Control

On both the client and server side a control function can be supplied to configure the decision mechanism for choosing the clients that broadcast synchronization signals.

Client side contract is a function accepting origin and socket parameters, which must return an object with a local property.

  function (origin <String>, socket <Object>} {
    return {
      local: <Boolean>
    }
  }

Absence of the object will cause a throw, absence of a local property will result in an assumed false value.

Server side contract is a function accepting origin, socket and clients parameters, which must return an object containing local and primary properties.

  function (origin <String>, socket <Object>, clients <Array>} {
    return {
      local: <Boolean>,
      primary: <socket Object>
    }
  }

The primary control socket should stay consistent, it's used to broadcast the current page to newly connected clients. We have to choose one socket to do this, otherwise clients are hit multiple times.

Absence of the object will cause a throw, absence of a local property will result in an assumed false value, absence of a primary property will prevent clients from receiving the current active slide upon loading.

Mediator executable

When bespoke-synchro is installed globally, the mediator can started via an executable:

npm install -g bespoke-synchro
bespoke-synchro-mediator --port 9999

License

MIT License

Sponsoship

Sponsored by nearForm