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

Commit 615820b

Browse files
committed
2 parents 27096ea + bba3420 commit 615820b

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ node_modules/
22
dist/
33
examples/
44
npm-debug.log
5+
.idea/

README.md

+22
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,28 @@ When users join a presence channel, their presence channel authentication data i
264264

265265
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.
266266

267+
Optionally, you can configure laravel-echo-server to publish an event on each update to a presence channel, by setting `databaseConfig.publishPresence` to `true`:
268+
269+
```json
270+
{
271+
"database": "redis",
272+
"databaseConfig": {
273+
"redis" : {
274+
"port": "6379",
275+
"host": "localhost"
276+
},
277+
"publishPresence": true
278+
}
279+
}
280+
```
281+
You can use Laravel's Redis integration, to trigger Application code from there:
282+
```php
283+
Redis::subscribe(['PresenceChannelUpdated'], function ($message) {
284+
var_dump($message);
285+
});
286+
```
287+
288+
267289
## Client Side Configuration
268290

269291
See the official Laravel documentation for more information. <https://laravel.com/docs/master/broadcasting#introduction>

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/database/redis.ts

+8
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,13 @@ export class RedisDatabase implements DatabaseDriver {
3737
*/
3838
set(key: string, value: any): void {
3939
this._redis.set(key, JSON.stringify(value));
40+
if(this.options.databaseConfig.publishPresence === true && /^presence-.*:members$/.test(key)) {
41+
this._redis.publish('PresenceChannelUpdated', JSON.stringify({
42+
"event": {
43+
"channel": key,
44+
"members": value
45+
}
46+
}));
47+
}
4048
}
4149
}

0 commit comments

Comments
 (0)