Skip to content

Commit 030b8ed

Browse files
committed
Change to support websocket JWT connections
1 parent 18c4b95 commit 030b8ed

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

app/Http/Controllers/Api/Client/Servers/WebsocketController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public function __invoke(Request $request, Server $server)
6363
->expiresAt($now->addMinutes(15)->getTimestamp())
6464
->withClaim('user_id', $request->user()->id)
6565
->withClaim('server_uuid', $server->uuid)
66+
->withClaim('permissions', ['connect', 'send-command', 'send-power'])
6667
->getToken($signer, new Key($server->node->daemonSecret));
6768

6869
$socket = str_replace(['https://', 'http://'], ['wss://', 'ws://'], $server->node->getConnectionAddress());

resources/scripts/plugins/Websocket.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class Websocket extends EventEmitter {
2525
// Connects to the websocket instance and sets the token for the initial request.
2626
connect (url: string) {
2727
this.url = url;
28-
this.socket = new Sockette(url, {
28+
this.socket = new Sockette(`${this.url}?token=${this.token}`, {
2929
onmessage: e => {
3030
try {
3131
let { event, args } = JSON.parse(e.data);
@@ -75,7 +75,6 @@ export class Websocket extends EventEmitter {
7575
this.socket && this.socket.send(JSON.stringify({
7676
event,
7777
args: Array.isArray(payload) ? payload : [ payload ],
78-
token: this.token || '',
7978
}));
8079
}
8180
}

0 commit comments

Comments
 (0)