Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
tlaverdure committed Sep 13, 2018
2 parents 27096ea + bba3420 commit 615820b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules/
dist/
examples/
npm-debug.log
.idea/
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,28 @@ When users join a presence channel, their presence channel authentication data i

While presence channels contain a list of users, there will be instances where a user joins a presence channel multiple times. For example, this would occur when opening multiple browser tabs. In this situation "joining" and "leaving" events are only emitted to the first and last instance of the user.

Optionally, you can configure laravel-echo-server to publish an event on each update to a presence channel, by setting `databaseConfig.publishPresence` to `true`:

```json
{
"database": "redis",
"databaseConfig": {
"redis" : {
"port": "6379",
"host": "localhost"
},
"publishPresence": true
}
}
```
You can use Laravel's Redis integration, to trigger Application code from there:
```php
Redis::subscribe(['PresenceChannelUpdated'], function ($message) {
var_dump($message);
});
```


## Client Side Configuration

See the official Laravel documentation for more information. <https://laravel.com/docs/master/broadcasting#introduction>
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/database/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,13 @@ export class RedisDatabase implements DatabaseDriver {
*/
set(key: string, value: any): void {
this._redis.set(key, JSON.stringify(value));
if(this.options.databaseConfig.publishPresence === true && /^presence-.*:members$/.test(key)) {
this._redis.publish('PresenceChannelUpdated', JSON.stringify({
"event": {
"channel": key,
"members": value
}
}));
}
}
}

0 comments on commit 615820b

Please sign in to comment.