Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
ludovic committed Nov 27, 2024
2 parents 632c02b + 9d623ef commit 7646411
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ window.Echo = new Echo({
broadcaster,
// replace the placeholders
host: 'wss://{api-ip}.execute-api.{region}.amazonaws.com/{stage}',
authEndpoint: '{auth-url}/broadcasting/auth', // Optional: Use if you have a separate authentication endpoint
bearerToken: '{token}', // Optional: Use if you need a Bearer Token for authentication
});
```

Expand Down
9 changes: 8 additions & 1 deletion js-src/Websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { AxiosResponse } from "axios";
import axios from 'axios';
import { Channel } from "./Channel";

export type Options = { authEndpoint: string, host: string, debug: boolean };
export type Options = { authEndpoint: string, host: string, bearerToken: string, auth: any, debug: boolean };

export type MessageBody = { event: string, channel?: string, data: object };

export class Websocket {
Expand Down Expand Up @@ -178,9 +179,15 @@ export class Websocket {
if (channel.name.startsWith('private-') || channel.name.startsWith('presence-')) {
this.options.debug && console.log(`Sending auth request for channel ${channel.name}`)

if (this.options.bearerToken) {
this.options.auth.headers['Authorization'] = 'Bearer ' + this.options.bearerToken;
}

axios.post(this.options.authEndpoint, {
socket_id: this.getSocketId(),
channel_name: channel.name,
}, {
headers: this.options.auth.headers || {}
}).then((response: AxiosResponse) => {
this.options.debug && console.log(`Subscribing to channels ${channel.name}`)

Expand Down

0 comments on commit 7646411

Please sign in to comment.