# socketio-transport

> socketio-transport will allow you to define request handlers on the server side and to access them from the client side.

Latest version **0.0.4** (published 2014-04-11) · 0 weekly downloads

## Install

```sh
npm install socketio-transport
pnpm add socketio-transport
yarn add socketio-transport
bun add socketio-transport
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2014-04-11 |
| First published | 2014-04-08 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Olivier Scherrer |
| Maintainers | podefr |
| Keywords | transport, request, handlers, listen, socket.io, socketio, server, client |

## Links

- npm: https://www.npmjs.com/package/socketio-transport
- Repository: git@github.com:cosmosio/socketio-transport
- Homepage: https://github.com/cosmosio/socketio-transport
- Issues: https://github.com/cosmosio/socketio-transport/issues
- npm.io page: https://npm.io/package/socketio-transport

## 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.4 (latest) — 2014-04-11
- 0.0.3 — 2014-04-09
- 0.0.2 — 2014-04-09
- 0.0.1 — 2014-04-08

## README

#Socketio-transport

socketio-transport will allow you to define request handlers (file, DB, ...) on the server side and to access them from the client side.

#Installation

```bash
npm install socketio-transport
```

#How to use

socketio-transport has a client-side and a server-side part, just like socket.io which it's based upon. It'll just wrap socket.io to provide a nice abstraction to make requests and open channels from the client side.

## Wrap the server side and define handlers

Require the server part of socketio-transport:

```js
var transport = require("socketio-transport").Server;
```

And define you request handlers:

```js
var handlers = {
    /**
     * payload is a JSON sent by the client
     * onData is the callback that will receive each update
     * onEnd will be called with the last update
     */
    test: function (payload, onEnd, onData) {
        setInterval(function () {
            onData((new Date));
        }, 200);
    }
}
```

Then register the socket.io that you want to use and add the handlers too. The handlers need to be wrapped in an observable-store, because they can be shared between several `transports` and they will know when handlers are added/removed/updated if needed.

```js
// the socket.io
var io = require("socket.io").listen(8000);

// The observable-store to wrap the handlers
var Store = require("observable-store");

// register socket.io and the handlers:
socketioTransport(io, new Store(handlers));
```

## Wrap the client side and query the handlers

Require the client part of socketio-transport

```js
var SocketioTransport = require("socketio-transport").Client;
```

Initialize it with the socket.io that you want to use:

```js
var transport = new SocketioTransport(io.connect("http://localhost:8000"));
```

And you're now free to query your request handlers:

```js
transport.listen("test", { ...}, function onData(data) {
    // do something with data
    console.log(data); // Date, triggered every 200ms
});
```

LICENSE
=======

MIT

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