1.0.3 • Published 5 years ago

@zfolk/adonis-wsex v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

adonis-wsex

Adonis provider for websocket check/exchange with authorized users

Requires

Installation

npm i -S @zfolk/adonis-wsex

Setup

Add as provider (start/app.js)

const providers = [
    '@zfolk/adonis-wsex/providers/WsExProvider'
]

Add socket channel (start/socket.js). Clients should subscribe to 'wsex'.

const WsEx = use('WsEx')

WsEx.channel().middleware('auth') // Adds channel/topic named 'wsex'

## Usage
> Broadcast to all connected users
```javascript
const WsEx = use('WsEx')
const event = 'message' // any string-named event
const data = { text: 'Text' } // any data|type serializable to json

WsEx.broadcast(event, data)

Emit to certain user by its id

const WsEx = use('WsEx')
const userId = 23 // if user is offline - nothing will be done
const event = 'message' // any string-named event
const data = { text: 'Text' } // any data|type serializable to json

WsEx.emit(userId, event, data)

> Get online user ids
```javascript
const WsEx = use('WsEx')

const userIds = WsEx.getOnline() // returns <Array> with ids

Check if user is online

const WsEx = use('WsEx')
const userId = 23 // user id needs to be checked

const online = WsEx.isOnline(userId) // returns , true === online

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago