1.50.0 • Published 7 months ago

@totemorg/socketio v1.50.0

Weekly downloads
-
License
ISC
Repository
-
Last release
7 months ago

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).

Install

npm install @totemorg/socketio
npm update

Start

npm run start ?					# List start options

Manage

npm run verminor				# Roll minor version
npm run vermajor				# Roll major version
npm run redoc					# Regen documentation
npm run pubminor				# republish as minor version
npm run pubmajor				# republish as major version

Usage

Acquire SocketIO as follows:

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

See the Program Reference for examples.

Program Reference

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:@totemorg/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

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> 
	
to define an ioClient name.

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:
	
	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

The client-side of socketio. The socketio interface is established when the server does a require( "socketio"). This require creates an endpoint at socketio from which the client imports its client via the following

<script src=socketio> tag.  Next we define the ioClient using this socketio.

Author: ACMESDS

SOCKETIO-CLIENT~io()

Make a connect request to the server at url||window.location.

Kind: inner method of SOCKETIO-CLIENT

Contacting, Contributing, Following

Feel free to

License

MIT


© 2012 ACMESDS

1.48.0

7 months ago

1.49.0

7 months ago

1.50.0

7 months ago

1.42.0

1 year ago

1.44.0

1 year ago

1.43.0

1 year ago

1.46.0

1 year ago

1.45.0

1 year ago

1.47.0

1 year ago

1.36.0

2 years ago

1.37.0

2 years ago

1.35.0

2 years ago

1.38.0

2 years ago

1.39.0

2 years ago

1.40.0

2 years ago

1.41.0

2 years ago

1.33.0

2 years ago

1.29.0

2 years ago

1.32.0

2 years ago

1.30.0

2 years ago

1.31.0

2 years ago

1.27.0

2 years ago

1.28.0

2 years ago

1.25.0

2 years ago

1.26.0

2 years ago

1.23.0

2 years ago

1.24.0

2 years ago

1.17.0

3 years ago

1.22.0

3 years ago

1.15.0

3 years ago

1.14.0

3 years ago

1.13.0

3 years ago

1.11.0

3 years ago

1.10.0

3 years ago

1.9.0

3 years ago