@@ -11,7 +11,8 @@ import { createClient } from "@supabase/supabase-js";
1111let Hooks = { } ;
1212Hooks . payload = {
1313 initRealtime (
14- channelName ,
14+ channel_name ,
15+ private_channel ,
1516 host ,
1617 log_level ,
1718 token ,
@@ -33,6 +34,10 @@ Hooks.payload = {
3334 } ,
3435 } ;
3536
37+ const privateChannel = private_channel
38+ ? private_channel . toLowerCase ( ) === "true"
39+ : false ;
40+
3641 this . realtimeSocket = createClient ( host , token , opts ) ;
3742
3843 if ( bearer != "" ) {
@@ -42,8 +47,8 @@ Hooks.payload = {
4247 // Join the Channel 'any'
4348 // Channels can be named anything
4449 // All clients on the same Channel will get messages sent to that Channel
45- this . channel = this . realtimeSocket . channel ( channelName , {
46- config : { broadcast : { self : true } } ,
50+ this . channel = this . realtimeSocket . channel ( channel_name , {
51+ config : { broadcast : { self : true } , private : privateChannel } ,
4752 } ) ;
4853
4954 // Hack to confirm Postgres is subscribed
@@ -131,7 +136,7 @@ Hooks.payload = {
131136 localStorage . setItem ( "host" , host ) ;
132137 localStorage . setItem ( "token" , token ) ;
133138 localStorage . setItem ( "log_level" , log_level ) ;
134- localStorage . setItem ( "channel" , channelName ) ;
139+ localStorage . setItem ( "channel" , channel_name ) ;
135140 localStorage . setItem ( "schema" , schema ) ;
136141 localStorage . setItem ( "table" , table ) ;
137142 localStorage . setItem ( "filter" , filter ) ;
@@ -187,12 +192,16 @@ Hooks.payload = {
187192 } ) ;
188193 } ,
189194
190- sendRealtime ( event , payload ) {
195+ sendRealtime ( event , payload , privateMessage ) {
191196 // Send a `broadcast` message over the Channel
192197 // All connected clients will receive this message if they're subscribed
193198 // to `broadcast` events and matching on the `event` name or using `*` to match all event names
199+
200+ let priv = privateMessage ? privateMessage . toLowerCase ( ) === "true" : false ;
201+
194202 this . channel . send ( {
195203 type : "broadcast" ,
204+ private : priv ,
196205 event : event ,
197206 payload : payload ,
198207 } ) ;
@@ -221,13 +230,15 @@ Hooks.payload = {
221230 bearer : localStorage . getItem ( "bearer" ) ,
222231 enable_presence : localStorage . getItem ( "enable_presence" ) ,
223232 enable_db_changes : localStorage . getItem ( "enable_db_changes" ) ,
233+ private_channel : localStorage . getItem ( "private_channel" ) ,
224234 } ;
225235
226236 this . pushEventTo ( "#conn_form" , "local_storage" , params ) ;
227237
228238 this . handleEvent ( "connect" , ( { connection } ) =>
229239 this . initRealtime (
230240 connection . channel ,
241+ connection . private_channel ,
231242 connection . host ,
232243 connection . log_level ,
233244 connection . token ,
@@ -241,7 +252,7 @@ Hooks.payload = {
241252 ) ;
242253
243254 this . handleEvent ( "send_message" , ( { message } ) =>
244- this . sendRealtime ( message . event , message . payload )
255+ this . sendRealtime ( message . event , message . payload , message . private_message )
245256 ) ;
246257
247258 this . handleEvent ( "disconnect" , ( { } ) => this . disconnectRealtime ( ) ) ;
0 commit comments