Cozy Realtime

npm version license travis npm downloads david-dm david-dm renovate


What’s cozy-realtime?

A simple way to have realtime using Websocket with cozy-stack.

Setup

Install

npm install --save cozy-realtime or yarn add cozy-realtime

API

subscribeAll(config, doctype, parse)

This method allow you to subscribe to realtime for all documents of a provided doctype. Here are the parameters:

Here is an example:

import realtime from 'cozy-realtime'

const subscription = await realtime.subscribeAll(cozy.client, 'io.mocks.mydocs')

// your code when a new document is created
subscription.onCreate(doc => doSomethingOnCreate(doc))
// your code when a document is updated
subscription.onUpdate(doc => doSomethingOnUpdate(doc))
// your code when a document is deleted
subscription.onDelete(doc => doSomethingOnDelete(doc))

// Unsubscribe from realtime
subscription.unsubscribe()

subscribe(config, doctype, doc, parse)

This method is exactly the same working as the previous subscribeAll() function but to listen only one document. Here are the parameters:

Here is an example:

import realtime from 'cozy-realtime'

const subscription = await realtime.subscribe(cozy.client, 'io.mocks.mydocs', myDoc)

// your code when your document is updated
subscription.onUpdate(doc => doSomethingOnUpdate(doc))
// your code when your document is deleted
subscription.onDelete(doc => doSomethingOnDelete(doc))

// Unsubscribe from realtime
subscription.unsubscribe()

Community

What’s Cozy?

cozy


[Cozy] is a platform that brings all your web services in the same private space. With it, your webapps and your devices can share data easily, providing you with a new experience. You can install Cozy on your own hardware where no one’s tracking you.

Get in touch

You can reach the Cozy Community by:

Maintainers

The maintainers for Cozy Realtime are Greg and kosssi !

License

cozy-realtime is distributed under the MIT license.