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

syncs-node

v1.0.1

Published

Syncs library for NodeJs

Downloads

10

Readme

syncs-browser

A JavaScript Library for Real-Time Web Applications

syncs-node is NodeJs module to work with Syncs.

Initalization

syncs-node is easy to setup.

  npm i syncs-node -S

Syncs classes are generated using TypeScript. TypeScript files are also published in npm package, so developers can write both server and client application using typescript.

JavaScript Initialize:

  let Syncs=require('syncs-node').Syncs;
  let io=new Syncs("ws//server-addserss/syncs");

TypeScrip Initialize using default export:

  import syncs from "syncs-node";
  let io=syncs("ws//server-addserss/syncs");

TypeScrip Initialize using Syncs class:

  import {Syncs} from "syncs-node";
  let io=new Syncs("ws//server-addserss/syncs");

The path parameter is required that determines Syncs server address. The second parameter is Syncs configs object with following properties:

  • autoConnect:boolean: If autoConnect is false then the Syncs instance will not connect to server on creation. To connect manuly to server developers should call io.connect() method. default value is true.
  • autoReconnect:boolean: This config makes the connection presistent on connection drop. default value is true.
  • reconnectDelay: number: time to wait befor each reconnecting try. default value is 10000.
  • debug:bolean: This parameter enables debug mode on client side. default value is false.

Handling connection

Syncs client script can automatically connect to Syncs server. If autoConnect config is set to false, the developer should connect manualy to server using connect method.

Using connect method developers can connect to defined server.

  io.connect();

Target application can establish connection or disconnect from server using provided methods.

  io.disconnect()

Developers can handle disconnect and close event with onDisconnect and onClose method.

    io.onDisconnect(()=>{
            
    })
    io.onClose(()=>{
            
    })

It's alos possible to check connection status using online property of Syncs instance.

  if(io.online){
      //do semething
  }

Abstraction Layers

Syncs provides four abstraction layer over its real-time functionality for developers.

1. onMessage Abstraction Layer

Developers can send messages using send method of Syncs instance to send JSON message to the server.Also all incoming messages are catchable using onMessage.

io.onConnection(client=>{
    io.send({text:"im ready"});
})
io.onMessage(message=>{
    alert(message.text);
})

2. Publish and Subscribe Abstraction Layer

With a Publish and Subscribe solution developers normally subscribe to data using a string identifier. This is normally called a Channel, Topic or Subject.

 io.publish('mouse-move-event',{x:xLocation,y:yLocation});
 io.subscribe('weather-update',updates=>{
   // update weather view
 });

3. Shared Data Abstraction Layer

Syncs provides Shared Data functionality in form of variable sharing. Shared variables can be accessible in tree level: Global Level, Group Level and Client Level. Only Client Level shared data can be write able with client.

To get Client Level shared object use shared method of Syncs instance.

  let info=io.shared('info');
  info.title="Syncs is cool!"

To get Group Level shared object use groupShared method of Syncs instance. First parameter is group name and second one is shared object name.

  let info=io.groupShared('vips','info');
  document.title=info.onlineUsers+" vip member are online";

To get Global Level shared object use globalShared method of Syncs instance.

  let settings=io.globalShared('settings');
  applyBackground(settings.background);

It's possible to watch changes in shared object by using shared object as a function.

  info((event)=>{
    document.title=info.title
  });

The callback function has two argument.

  • values:object: an object that contains names of changed properties and new values.
  • by:string a string variable with two value ( 'server' and 'client') which shows who changed these properties.

4. Remote Method Invocation (RMI) Abstraction Layer

With help of RMI developers can call and pass argument to remote function and make it easy to develop robust and web developed application. RMI may abstract things away too much and developers might forget that they are making calls over the wire.

Before calling remote method from server ,developer should declare the function on client script.

functions object in Syncs instance is the place to declare functions.

io.functions.showMessage=function(message) {
  alert(message);
}

To call remote method on server use remote object.

  io.remote.setLocation(latitude,longitude)

The remote side can return a result (direct value or Promise object) which is accessible using Promise object returned by caller side.

    io.functions.askName=function(title){
        return prompt(title);
    }
io.functions.startQuiz=function(questions,quizTime){
    return new Promise((res,rej)=>{
        // start quiz
        setTimeout(()=>{
            res(quizResult);
        },quizTime);

    })
}
  io.remote.getWeather(cityName).then(forcast=>{
      // show forcast result
  })