🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@totemstan/socketio

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@totemstan/socketio

Replacement for buggy socket.io

latest
Source
npmnpm
Version
1.7.0
Version published
Maintainers
1
Created
Source

SOCKETIO

Provides a form-fit-functional replacement for the notoriously buggy socket.io and its socket.io-client client counterpart. Like its socket.io predecessors, SocketIO provides json-based web sockets, though it also has hooks to support binary sockets (for VoIP, video, etc) applications. SocketIO provides both a server-side and client-side modules that mimic the socket.io specification (less the bugs of course).

Manage

npm install @totemstan/socketio	# install
npm run start [ ? | $ | ...]	# Unit test
npm run verminor				# Roll minor version
npm run vermajor				# Roll major version
npm run redoc					# Regen documentation

Usage

Acquire SocketIO as follows:

const SIO = require("@totemstan/socketio");

See the Program Reference for examples.

Program Reference

Open/Close ## Modules
SOCKETIO

Replaces the buggy socket.io and socket.io-client modules. Documented in accordance with jsdoc.

ref: https://medium.com/hackernoon/implementing-a-websocket-server-with-node-js-d9b78ec5ffa8

SOCKETIO-CLIENT

Replaces the buggy socket.io and socket.io-client modules found in the public.

SOCKETIO

Replaces the buggy socket.io and socket.io-client modules. Documented in accordance with jsdoc.

ref: https://medium.com/hackernoon/implementing-a-websocket-server-with-node-js-d9b78ec5ffa8

Requires: module:@totemstan/enums, module:crypto
Author: ACMESDS
Example

On the server:

	const SIO = require("socketio");
	IO = SIO(server);					// connects socketIO to your nodejs server
	
	IO.on( "connect", socket => {		// the client automatically emits a "connect" request when it calls io()  
	
		socket.on(  "CHANNEL", (req,socket) => {			// intercepts client request made on socket to this CHANNEL
			console.log( "here is the client's request", req ); 
			socket.emit({ message: "a response" });
			IO.emit({ message: "a message for everyone!" });
			IO.emitOthers("SkipThisClient", { message: "a message for everyone!" });		// useful emit extension
			IO.clients["someone@totem.org"].emit({ message: "you get an extra message"});
		});
		
		// etc for other CHANNELs 

	});	
	IO.emit({ .... })  			// to emit a request to all clients

On the client:

	// <script type="text/javascript, src="/socketio/socketio-client.js"></script>

	const
		ioSocket = io();			// connect to socketIO by emitting a "connect" request
		ioClient = "myClientName";	// set a client name to identify this socket

	ioSocket.emit("CHANNEL", {		// send request to server side on its CHANNEL
		...
	});
	
	ioSocket.on("CHANNEL", req => {
		console.log("server sent this request", req);
	});
	

Example

On the server:

	const
		SOCKETIO = require("socketio"),
		SIO = SOCKETIO(server); 	// establish sockets on provided HTTP server

	SIO.on("connect", socket => {  	// define socket listeners when client calls the socketio-client io()
		console.log("listening to sockets");

		socket.on( "join", (req,socket) => {	// trap client "join" request
		});

		// etc
	});
	

On the client:
	// The socketio interface is established when the server does a require( "socketio" ) to create a 
	// socketio = "/socketio/socketio-client.js" endpoint from which the client imports its client via a 
	// <script src=socketio> and defines a default ioClient name.

	const
		iosocket = io(); 					// connect to socketio 
		ioClient = "somewhere@org.com";		// default client nmae

		iosocket.emit( "join", {			// send join request to server
			client: ioClient,				// usually provide with request 
			message: "can I join please?"	// optional connection info
		}); 

SOCKETIO-CLIENT

Replaces the buggy socket.io and socket.io-client modules found in the public.

Author: ACMESDS

Contacting, Contributing, Following

Feel free to

License

MIT

© 2012 ACMESDS

Keywords

web

FAQs

Package last updated on 06 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts