# datachannel.io

> node.js realtime signaling server

Latest version **0.0.15** (published 2014-01-12) · 0 weekly downloads

## Install

```sh
npm install datachannel.io
pnpm add datachannel.io
yarn add datachannel.io
bun add datachannel.io
```

## Health

**Score 10/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.15 |
| Published | 2014-01-12 |
| First published | 2013-02-23 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Known vulnerabilities | 0 (+7 in 4 direct dependencies) |
| Install scripts | no |
| Maintainers | marcolanaro |
| Keywords | realtime, framework, websocket, webRTC, events, socket, io |

## Links

- npm: https://www.npmjs.com/package/datachannel.io
- npm.io page: https://npm.io/package/datachannel.io

## Dependencies (5)

- [send](https://npm.io/package/send.md) ~0.1.0
- [cookie](https://npm.io/package/cookie.md) 0.1.0
- [connect](https://npm.io/package/connect.md) 2.9.0
- [socket.io](https://npm.io/package/socket.io.md) 0.9.12
- [connect-redis](https://npm.io/package/connect-redis.md) 1.4.6

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 0.0.15 (latest) — 2014-01-12
- 0.0.14 — 2014-01-09
- 0.0.13 — 2014-01-04
- 0.0.12 — 2014-01-04
- 0.0.11 — 2014-01-03
- 0.0.10 — 2014-01-03
- 0.0.9 — 2013-12-31
- 0.0.8 — 2013-12-27
- 0.0.7 — 2013-12-17
- 0.0.6 — 2013-12-14
- 0.0.5 — 2013-11-24
- 0.0.4 — 2013-10-13
- 0.0.3 — 2013-03-02
- 0.0.2 — 2013-02-24
- 0.0.1 — 2013-02-23

## README

Datachannel.io is inspired by the amazing socket.io framework and implements a real-time communication using the WebRTC technology.
Peers are directly connected and datas are exchanged between clients without passing throug the server.

Socket.io has two purposes:
* Serve signals between clients needed to coordinate the communication.
* In case peer-to-peer communication fails or your browser does not support WebRTC, socket.io serve also the data message.

## Installing
	npm install datachannel.io
## On the Server
	var server = require('http').createServer();
	var dc = require('dataChannel.io').listen(server, options);

	server.listen(8080);
#### Redis Store
If you want to implement sessions management or horizontal scaling you need a redis server.

Note: By default, redis-server binds to local only. Edit redis.conf to comment out this option or you will receive an ECONNECTREFUSED error. The line to comment out is:
     bind 127.0.0.1

	var server = require('http').createServer();
	var dc = require('dataChannel.io').listen(server, {
		redis: {port: [INTEGER], host: [STRING], options: { pass: [STRING] }},
	});

	server.listen(8080);

#### Static File
If you do not want to serve the static client file at `/datachannel.io/datachannel.io.js` you need to add the parameter `static: false`.

	var server = require('http').createServer();
	var dc = require('dataChannel.io').listen(server, {
		static: false
	});

	server.listen(8080);

#### Add a Namespace

You need to add at least one namespace:

	dc.addNameSpace([STRING], {
		session: {
			cookie: {name: [STRING], secret: [STRING]},
			auth: function(session) {
				return true;
			}
		}
	});


Session management is optional, if you want to use it you need a Redis server configured. The `session` object has this parameters:
* `cookie` [mandatory]: object with `name` of the cookie and `secret` key
* `auth` [optional, default as `return true`]: function that return the authorization to use the socket.io server based on the current `session`.


## On the Client
#### index.html
	<!DOCTYPE html>
	<html>
		<head></head>
		<body>
			<script src="http://<yourHost>/datachannel.io/datachannel.io.js"></script>
			<script>
				var datachannel = new DataChannel({
					socketServer: 'http://<yourHost>'
				});
			</script>
		</body>
	</html>
#### Initialization
The parameters of the `new DataChannel(object)` are:
* `socketServer` [mandatory]: the address of the socket server used to serve signals between clients
* `nameSpace` [optional, default as `'dataChannel'`]: namespace of the socket.io server
* `rtcServers` [optional, default as `null`]: RTC Servers

#### Join a Room
	datachannel.join("room");
#### Leave a Room
	datachannel.leave("room");
#### Send a Message
	datachannel.in("room").emit("chat", {text: 'Hi!'});
#### Get a Message
	datachannel.in("room").on("chat", function(data) {
		console.log(data);
	});

### ToDo

- SSL

Tested on Chrome v25 and Firefox v20.

Some examples at [https://github.com/marcolanaro/DataChannel.IO-Examples](https://github.com/marcolanaro/DataChannel.IO-Examples).


More information at [http://www.datachannel.io](http://www.datachannel.io).

## License

MIT

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