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

sync-ws

v0.9.15

Published

Multiplayer Game Client for the Browser

Downloads

41

Readme

Platforms

This client works on these platforms:

Usage

Connecting to server:

import * as Colyseus from "colyseus.js";

var client = new Colyseus.Client('ws://localhost:2657');

Joining to a room:

var room = client.join("room_name");
room.onJoin.add(function() {
    console.log(client.id, "joined", room.name);
});

Listening to room state change:

Here comes the most powerful feature of the client. You can listen to every state update in the server-side, and bind them into client-side functions.

The first parameter is the path of the variable you want to listen to. When you provide placeholders (such as :number, :id, :string) to the path, they will populate the function with the value found on it. See examples below.

Listening to entities being added/removed from the room:

room.listen("entities/:id", (change) => {
    console.log(`new entity ${change.path.id}`, change.value);
});

Listening to entity attributes being added/replaced/removed:

room.listen("entities/:id/:attribute", (change) => {
    console.log(`entity ${change.path.id} changed attribute ${change.path.attribute} to ${change.value}`);
});

Other room events

Room state has been updated:

room.onStateChange.add(function(state) {
  console.log(room.name, "has new state:", state)
})

Message broadcasted from server or directly to this client:

room.onMessage.add(function(message) {
  console.log(client.id, "received on", room.name, message)
});

Server error occurred:

room.onError.add(function() {
  console.log(client.id, "couldn't join", room.name)
});

The client left the room:

room.onLeave.add(function() {
  console.log(client.id, "left", room.name)
});

Useful links

React Native compatibility

This client works with React Native. You need to install some aditional dependencies for compatibility and assign window.localStorage to AsyncStorage.

  • Install react-native-browser-polyfill (npm install react-native-browser-polyfill)
  • Install and follow rn-nodeify installation instructions (npm install rn-nodeify)
// App.js
import 'react-native-browser-polyfill';
import './shim';
import { AsyncStorage } from 'react-native';
window.localStorage = AsyncStorage;

Another caveat is that you can only join rooms after the first connection open.

var client = new Colyseus.Client('ws://localhost:2657');

client.onOpen.add(() => {
    let room = client.join("your_room");
})

License

MIT