# @totemorg/socketio

> socket.io

Latest version **1.50.0** (published 2024-11-23) · ISC license · 0 weekly downloads

## Install

```sh
npm install @totemorg/socketio
pnpm add @totemorg/socketio
yarn add @totemorg/socketio
bun add @totemorg/socketio
```

## Health

**Score 30/100 (F)** — status: maintenance-mode.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.50.0 |
| Published | 2024-11-23 |
| First published | 2022-10-16 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 22.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | ACMESDS |
| Maintainers | totem4, totem3, totem2, totem1 |

## Links

- npm: https://www.npmjs.com/package/@totemorg/socketio
- Repository: https://totem-man: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@github.com/totem-man/socketio
- Homepage: https://github.com/totem-man/socketio#readme
- Issues: https://github.com/totem-man/socketio/issues
- npm.io page: https://npm.io/package/@totemorg/socketio

## Dependencies (1)

- [@totemorg/core](https://npm.io/package/@totemorg/core.md) ^1.2.0

## Recent versions

- 1.50.0 (latest) — 2024-11-23
- 1.49.0 — 2024-11-23
- 1.48.0 — 2024-11-23
- 1.47.0 — 2024-05-27
- 1.46.0 — 2024-05-25
- 1.45.0 — 2024-05-25
- 1.44.0 — 2024-05-25
- 1.43.0 — 2024-05-25
- 1.42.0 — 2024-05-24
- 1.41.0 — 2023-10-31
- 1.40.0 — 2023-10-31
- 1.39.0 — 2023-10-31
- 1.38.0 — 2023-10-31
- 1.37.0 — 2023-10-31
- 1.36.0 — 2023-10-31
- … 20 more at https://npm.io/package/@totemorg/socketio/versions

## README

# [SOCKETIO](https://www.npmjs.com/package/@totemorg/socketio)

Provides a form-fit-functional replacement for the notoriously buggy [socket.io](https://www.npmjs.com/package/socket.io) 
(and its [socket.io-client](https://www.npmjs.com/package/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](https://socket.io/docs/v3/client-initialization/)
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
<details>
<summary>
<i>Open/Close</i>
</summary>
## Modules

<dl>
<dt><a href="#module_SOCKETIO">SOCKETIO</a></dt>
<dd><p>Replaces the buggy socket.io and socket.io-client modules.
Documented in accordance with <a href="https://jsdoc.app/">jsdoc</a>.</p>
<p>ref: <a href="https://medium.com/hackernoon/implementing-a-websocket-server-with-node-js-d9b78ec5ffa8">https://medium.com/hackernoon/implementing-a-websocket-server-with-node-js-d9b78ec5ffa8</a></p>
</dd>
<dt><a href="#module_SOCKETIO-CLIENT">SOCKETIO-CLIENT</a></dt>
<dd><p>The client-side of <a href="https://www.npmjs.com/package/@totemorg/socketio">socketio</a>.
    The socketio interface is established when the server does a require( &quot;socketio&quot;).  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.</p>
</dd>
</dl>

<a name="module_SOCKETIO"></a>

## SOCKETIO
Replaces the buggy socket.io and socket.io-client modules.
Documented in accordance with [jsdoc](https://jsdoc.app/).

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

**Requires**: <code>module:[@totemorg/enums](https://www.npmjs.com/package/@totemorg/enums)</code>, <code>module:[crypto](https://nodejs.org/docs/latest/api/)</code>  
**Author**: [ACMESDS](https://totemorg.github.io)  
**Example**  
```js
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**  
```js
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
		}); 
```
<a name="module_SOCKETIO-CLIENT"></a>

## SOCKETIO-CLIENT
The client-side of [socketio](https://www.npmjs.com/package/@totemorg/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](https://totemorg.github.io)  
<a name="module_SOCKETIO-CLIENT..io"></a>

### SOCKETIO-CLIENT~io()
Make a connect request to the server at url||window.location.

**Kind**: inner method of [<code>SOCKETIO-CLIENT</code>](#module_SOCKETIO-CLIENT)  
</details>

## Contacting, Contributing, Following

Feel free to 
* submit and status [TOTEM issues](http://totem.hopto.org/issues.view) 
* contribute to [TOTEM notebooks](http://totem.hopto.org/shares/notebooks/) 
* revise [TOTEM requirements](http://totem.hopto.org/reqts.view) 
* browse [TOTEM holdings](http://totem.hopto.org/) 
* or follow [TOTEM milestones](http://totem.hopto.org/milestones.view) 

## License

[MIT](LICENSE)

* * *

&copy; 2012 ACMESDS

---
_Source: https://npm.io/package/@totemorg/socketio · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
