# socket.io-pingpong

> Shortcut to on and emit. Pingpong as you receive the event and returns in the same role

Latest version **0.1.3** (published 2016-11-08) · ISC license · 0 weekly downloads

## Install

```sh
npm install socket.io-pingpong
pnpm add socket.io-pingpong
yarn add socket.io-pingpong
bun add socket.io-pingpong
```

## 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.1.3 |
| Published | 2016-11-08 |
| First published | 2016-08-30 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Philippe Assis |
| Maintainers | philippeassis |
| Keywords | socket, pingpong, ping-pong, socket.io |

## Links

- npm: https://www.npmjs.com/package/socket.io-pingpong
- Repository: https://github.com/PhilippeAssis/socket.io-pingpong
- Homepage: https://github.com/PhilippeAssis/socket.io-pingpong#readme
- Issues: https://github.com/PhilippeAssis/socket.io-pingpong/issues
- npm.io page: https://npm.io/package/socket.io-pingpong

## 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.1.3 (latest) — 2016-11-08
- 0.1.2 — 2016-11-08
- 0.1.1 — 2016-10-02
- 0.1.0 — 2016-10-02
- 0.0.5 — 2016-10-01
- 0.0.4 — 2016-10-01
- 0.0.3 — 2016-08-30
- 0.0.2 — 2016-08-30
- 0.0.1 — 2016-08-30

## README

# Socket.io-PingPong

Shortcut to on and emit. Pingpong as you receive the event and returns in the same role.

## Reason:

With socket "emit" I requested and received the data and then to "emit". I decided to reduce the process by creating the PingPong

## Install

`npm install --save socket.io-pingpong`

## Features

You can use ping pong or pp to call the methods

- **emit(name, args, callback)** Same socket.emit, but returns a given value on the server callback
- **on(name, callback)** socket.on the same as, but performs emit passing to the callback

## Example

### server.js

```javascript
var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);
var pingpong = require('socket.io-pingpong');

server.listen(8888); // you port

app.use(pingpong());

io.on('connection', function(socket) {
    var socket = pingpong(socket);

    socket.pp.on('name', function(value) {
        return value + " Assis";
    })

    socket.pp.emit('age', 27, function(age) {
        console.log('age:', age);
    })

});
```

### client.html

```html
<script src="/socket.io/socket.io.js"></script>
<script src="/pingpong.js"></script>

<script type="text/javascript">
    var socket = pingpong(io.connect());

    socket.pp.emit('name', 'philippe', function(name) {
        console.log('name:', name)
    })


    socket.pp.on('age', function(data) {
        return ++data
    })

</script>
```

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