-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchannels.php
61 lines (49 loc) · 2.16 KB
/
channels.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/*
* This file is part of RootDB.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* AUTHORS
* PORQUET Sébastien <[email protected]>
*/
use App\Models\User;
use Illuminate\Support\Facades\Broadcast;
/*
|--------------------------------------------------------------------------
| Public channels
|--------------------------------------------------------------------------
*/
// Used when a report is displayed from another host.
Broadcast::channel('public.user.{user_id}', function ($public_user_id) {
return true;
}, ['guards' => ['sanctum']]);
/*
|--------------------------------------------------------------------------
| Private channels
|--------------------------------------------------------------------------
*/
// * send results to view / reports with auto-refresh enabled.
// * send updated API data like groups, reports, view, parameters & co.
Broadcast::channel('organization.{organization_id}', function (User $user, int $organization_id) {
return $user->currentOrganizationLoggedUser->organization_id === $organization_id;
}, ['guards' => ['sanctum']]);
// * send results to views
// * send results to SQL console (for dev only)
Broadcast::channel('user.{web_socket_session_id}', function (User $user, string $web_socket_session_id) {
if (session()->get('currentOrganizationLoggedUser') !== null) {
return unserialize(session()->get('currentOrganizationLoggedUser'))->web_socket_session_id === $web_socket_session_id;
}
return false;
}, ['guards' => ['sanctum']]);