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

gamesocket.io

v1.3.22

Published

Simple event-oriented API for uWebSocket.js

Downloads

53

Readme

gamesocket.io

What is it?

Simple event-driven WebSocket server API based on uWebSocket.js

Features

Built-in aliases

Package provides a simple alias map, which is very useful when you need to find a socket ID by given name

//js

/* initialization code... */

app = io()

var socketAlias = ...
var socketId = ...

app.aliases.set(socketId, socketAlias)
ap.aliases.swap(socketAlias, 'someNewAlias')
app.aliases.getId('someNewAlias')

Namespace support

You can use many namespaces depending on your needs.

//js

import { Server } from 'gamesocket.io'

//emit to custom room in test namespace
Server.of('test').control('room').emit('someEvent')

//emit to custom socket in admin namespace
Server.of('admin').control(socketId).emit('someEvent')

Adaptive destination controller

You can use rooms and sockets in much ways.

//js

//create test namespace
var test = app.namespace('test')

//Sockets with ids 1, 2 join rooms 1, 2
test.control(['room1', 'room2']).join([id1, id2])

//Emits event to rooms 1, 2
test.control(['room1', 'room2']).emit('someEvent')

//Emits event to room
test.control('room').emit('someEvent')

//Emits event to sockets with ids 1, 2
test.control([id1, id2]).emit('someEvent')

//Sockets with ids 1, 2 join room
test.control([id1, id2]).join('room')

//Sockets with id1 leaves room
test.control(id1).leave('room')

Convenient data manager

All packets shall have same structure:

//typescript
export declare interface IDataEscort extends IEscort<finalData> {
  get(property: string): finalData | undefined
  get isPrimitive(): boolean
}

It means that all handlers could use same methods to auto-decode and parse socket binary data.

For example:

//js

/*
  * Suppose packet was
  * {
  *   event: login
  *   data: {
  *     login: 'anAwesomeName',
  *     password: 'hardPassword'
  *   }
  * }
*/

/* initialization code... */

test.on('login', (socketId, manager) => {
  var login = manager.get('data/login')
  var password = manager.get('data/password')

  if(login == 'anAwesomeName' && password == "hardPassword")
  // ...
})

Installation

// With NPM

npm install gamesocket.io

How to use

The following example creates gamesocket.io websocket server which listening on port 3000.

import io from 'gamesocket.io'

var app = io()
var main = io.of('main')
main.on('someEvent', (escort) => {
  /**
   * {
   *   event: 'someEvent',
   *   alias: 'test'
   * }
  */
  console.log(escort.event == 'someEvent')
  var alias = manager.get('alias')

  SocketPool.Aliases.set(socketId, alias)
})

Server.listen(3000, (listenSocket) => {
  if (listenSocket) console.log('Listening on 3000')
})

What's next?

In the near future the package will be overgrown with tests and optimized

And soon I probbably add next features:

  1. ~~Custom packet structure configuration~~
  2. ~~uWebSocket websocket configuration support~~
  3. Node.js worker support

And more...

If you want to help, please write on [email protected]