Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: check for private key on public Channel and error #1125

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ If you're using the default tenant, the URL is `ws://realtime-dev.localhost:4000
| JANITOR_CLEANUP_CHILDREN_TIMEOUT | number | Timeout for each async task for janitor cleanup |
| JANITOR_CHUNK_SIZE | number | Number of tenants to process per chunk. Each chunk will be processed by a Task |
| METRICS_CLEANER_SCHEDULE_TIMER_IN_MS | number | Time in ms to run the Metric Cleaner task |

## WebSocket URL
The WebSocket URL is in the following format for local development: `ws://[external_id].localhost:4000/socket/websocket`

Expand Down Expand Up @@ -237,6 +238,7 @@ This is the list of operational codes that can help you understand your deployme
| ErrorOnRpcCall | Error when calling another realtime node |
| ErrorExecutingTransaction | Error executing a database transaction in tenant database |
| SynInitializationError | Our framework to syncronize processes has failed to properly startup a connection to the database |
| PrivateKeyPublicChannelError | Incoming private message found on public Channel |
| JanitorFailedToDeleteOldMessages | Scheduled task for realtime.message cleanup was unable to run |
| UnknownErrorOnController | An error we are not handling correctly was triggered on a controller |
| UnknownErrorOnChannel | An error we are not handling correctly was triggered on a channel |
Expand Down
23 changes: 17 additions & 6 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import { createClient } from "@supabase/supabase-js";
let Hooks = {};
Hooks.payload = {
initRealtime(
channelName,
channel_name,
private_channel,
host,
log_level,
token,
Expand All @@ -33,6 +34,10 @@ Hooks.payload = {
},
};

const privateChannel = private_channel
? private_channel.toLowerCase() === "true"
: false;

this.realtimeSocket = createClient(host, token, opts);

if (bearer != "") {
Expand All @@ -42,8 +47,8 @@ Hooks.payload = {
// Join the Channel 'any'
// Channels can be named anything
// All clients on the same Channel will get messages sent to that Channel
this.channel = this.realtimeSocket.channel(channelName, {
config: { broadcast: { self: true } },
this.channel = this.realtimeSocket.channel(channel_name, {
config: { broadcast: { self: true }, private: privateChannel },
});

// Hack to confirm Postgres is subscribed
Expand Down Expand Up @@ -131,7 +136,7 @@ Hooks.payload = {
localStorage.setItem("host", host);
localStorage.setItem("token", token);
localStorage.setItem("log_level", log_level);
localStorage.setItem("channel", channelName);
localStorage.setItem("channel", channel_name);
localStorage.setItem("schema", schema);
localStorage.setItem("table", table);
localStorage.setItem("filter", filter);
Expand Down Expand Up @@ -187,12 +192,16 @@ Hooks.payload = {
});
},

sendRealtime(event, payload) {
sendRealtime(event, payload, privateMessage) {
// Send a `broadcast` message over the Channel
// All connected clients will receive this message if they're subscribed
// to `broadcast` events and matching on the `event` name or using `*` to match all event names

let priv = privateMessage ? privateMessage.toLowerCase() === "true" : false;

this.channel.send({
type: "broadcast",
private: priv,
event: event,
payload: payload,
});
Expand Down Expand Up @@ -221,13 +230,15 @@ Hooks.payload = {
bearer: localStorage.getItem("bearer"),
enable_presence: localStorage.getItem("enable_presence"),
enable_db_changes: localStorage.getItem("enable_db_changes"),
private_channel: localStorage.getItem("private_channel"),
};

this.pushEventTo("#conn_form", "local_storage", params);

this.handleEvent("connect", ({ connection }) =>
this.initRealtime(
connection.channel,
connection.private_channel,
connection.host,
connection.log_level,
connection.token,
Expand All @@ -241,7 +252,7 @@ Hooks.payload = {
);

this.handleEvent("send_message", ({ message }) =>
this.sendRealtime(message.event, message.payload)
this.sendRealtime(message.event, message.payload, message.private_message)
);

this.handleEvent("disconnect", ({}) => this.disconnectRealtime());
Expand Down
Loading
Loading