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

evsocket-client

v1.0.212

Published

EvSocket is abstracted WebSocket module with event driven interface and rich functinalities.

Downloads

45

Readme

EvSocket-Client

Why use this?

There is well-known alternative for this module, Socket.io, but unfortunately Socket.io doesn't support React Native, because it uses Node.js features inside. This module built for provide highly abstracted WebSocket interface without any Node.js related features, only used pure JavaScript features. When I was used WebSocket with vanila JS, it was really hard to make something rich. EvSocket provides similar interface like Socket.io with only uses WebSocket + JavaScript features so it is safe to use any WebSocket supporting JavaScript platform.

About

Client module for evsocket. Abstracted WebSocket module with event driven interface and rich functionalities. See full example here.

Features

  • Event Driven Interface
  • Easy Authentication
  • Binary Transmission
  • Middlewares
  • Channel system(like Room in Socket.io)
  • Socket Broadcasting
  • And more...!

Updates

  • [1.0.212] Fixed that getting Blob instead of ArrayBuffer when binary data received.

API

constructor EvSocket(string uri, object options)

Create new EvSocket. Available options are:

  • string protocol: Set protocol
var socket = new EvSocket('ws://localhost:3000');
socket.on('open', function() {
	console.log('Connected as ' + socket.id);
});

EvSocket.prototype.close(void)

Close WebSocket.

var socket = new EvSocket('ws://localhost:3000');
socket.on('open', function() {
	console.log('Connected as ' + socket.id);
	socket.close();
});

EvSocket.prototype.send(string evName, object data)

Send the data with event name to client.

var socket = new EvSocket('ws://localhost:3000');
...
socket.send('some-server-event', { a: 1, b: 2});

EvSocket.prototype.sendBinary(string evName, ArrayBuffer data)

EvSocket.prototype.sendBinary(string evName, TypedArray data)

Send the binary data with event name to client.

var socket = new EvSocket('ws://localhost:3000');
...
socket.sendBinary('some-server-event', new Uint8Array([1,2,3,4,5,6,7,8]));

EvSocket.prototype.on(string evName, function fn)

Add event listener.

EvSocket.prototype.once(string evName, function fn)

Add event listener that execute only once and delete itself automatically.

EvSocket.prototype.off(string evName[, function fn])

Remove event listener. If fn argument is undefined, remove all listeners in specified event name.

EvSocket.prototype.emit(string evName[, object data])

Fires event of server socket.

EvSocket.prototype.join(string channelName)

Join the specified channel.

var socket = new EvSocket('ws://localhost:3000');

socket.on('channeljoin', (channelName) {
	console.log(channelName);
	socket.leave();
});

socket.on('channelleave', () => {
	console.log('Channel left.');
});

socket.join('channel1');

EvSocket.prototype.leave(void)

Leave the current channel.

var socket = new EvSocket('ws://localhost:3000');

socket.on('channeljoin', (channelName) {
	console.log(channelName);
	socket.leave();
});

socket.on('channelleave', () => {
	console.log('Channel left.');
});

socket.join('channel1');

EvSocket.prototype.broadcast(string evName[, object data])

Broadcast message to users who currently in same channel.

var socket = new EvSocket('ws://localhost:3000');
socket.on('open', () => {
	socket.join('channel1');
});
socket.on('channeljoin', (channelName) => {
	socket.broadcast('chat', `User ${socket.id} joined to ${channelName}.`);
});

Events

You can use any name of the event, except these default events. These default events are triggering by EvSocket directly.

onopen

Fired on EvSocket is ready.

onauthenticated

Fired on EvSocket passed authentication.

onunauthorized

Fired on EvSocket failed authentication. After this event occurs, socket will close.

onclose

Fired on socket closed. Arguments are code and reason, please check this: https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent#Status_codes

onerror

Fired on error occured. Has one argument, error object.

onchanneljoin

Fired on user joined channel.

onchannelleave

Fired on user left channel.