# cozy-realtime-adapter

> A simple binder from cozy-data-system's events to backbone models

Latest version **1.0.2** (published 2016-02-22) · BSD license · 0 weekly downloads

## Install

```sh
npm install cozy-realtime-adapter
pnpm add cozy-realtime-adapter
yarn add cozy-realtime-adapter
bun add cozy-realtime-adapter
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2016-02-22 |
| First published | 2013-04-23 |
| Weekly downloads | 0 |
| License | BSD |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Romain |
| Maintainers | aenario, cozy, mycozycloud |

## Links

- npm: https://www.npmjs.com/package/cozy-realtime-adapter
- Repository: https://github.com/cozy/cozy-realtime-adapter
- Issues: https://github.com/cozy/cozy-realtime-adapter/issues
- npm.io page: https://npm.io/package/cozy-realtime-adapter

## Dependencies (3)

- [axon](https://npm.io/package/axon.md) 0.6.1
- [printit](https://npm.io/package/printit.md) 0.1.15
- [socket.io](https://npm.io/package/socket.io.md) 1.4.5

## Recent versions

- 1.0.2 (latest) — 2016-02-22
- 1.0.1 — 2015-04-21
- 1.0.0 — 2015-02-27
- 0.11.4 — 2014-12-11
- 0.11.3 — 2014-06-30
- 0.11.2 — 2014-02-05
- 0.12.0 — 2013-09-29
- 0.11.1 — 2013-09-05
- 0.11.0 — 2013-06-12
- 0.10.0 — 2013-05-27
- 0.9.0 — 2013-05-27
- 0.0.8 — 2013-04-26
- 0.0.7 — 2013-04-25
- 0.0.6 — 2013-04-25
- 0.0.5 — 2013-04-25
- … 4 more at https://npm.io/package/cozy-realtime-adapter/versions

## README

# Realtime adapter

Helper library for interaction with cozy-data-system data changes notifications

##Server-Side : Axon -> Socket.io

Usage :

```javascript
americano.start(options, function(app, server){
    app.server = server

    RealtimeAdapter = require('cozy-realtime-adapter')

    // notification events should be proxyed to client
    realtime = RealtimeAdapter(app, ['notification.*']);

    // custom callback for alarm events
    realtime.on('alarm.*', function(event, msg){
        // event = 'alarm.update' or 'alarm.create' or 'alarm.delete'
        // msg = id of the updated alarm
    });
});
```


##Client-Side : Socket.io -> Backbone Models manipulations

Basic Usage :

```html
<script src="cozy-realtime-adapter.js"></script>
```

```coffee
class SocketListener extends CozySocketListener

    models:
        'notification': Notification

    events: [
        'notification.create', 'notification.update', 'notification.delete'
    ]

    onRemoteCreate: (model) ->
        @collection.add model if # should model be in @collection ?

    onRemoteDelete: (model) ->
        @collection.remove model

sl = new SocketListener()

sl.watch myNotificationCollection
```

For more complex usages, refer to the code of cozy applications


## What is Cozy?

![Cozy Logo](https://raw.github.com/cozy/cozy-setup/gh-pages/assets/images/happycloud.png)

[Cozy](https://cozy.io) is a platform that brings all your web services in the
same private space.  With it, your web apps and your devices can share data
easily, providing you
with a new experience. You can install Cozy on your own hardware where no one
profiles you. You install only the applications you want. You can build your
own one too.

## Community 

You can reach the Cozy community via various support:

* IRC #cozycloud on irc.freenode.net
* Post on our [Forum](https://forum.cozy.io)
* Post issues on the [Github repos](https://github.com/cozy/)
* Via [Twitter](https://twitter.com/mycozycloud)

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