// Join a room/topic. Can be anything except for 'realtime'.
const channelA = clientA.channel('room-1')
// Simple function to log any messages we receive
function messageReceived(payload) {
console.log(payload)
}
// Subscribe to the Channel
channelA
.on(
'broadcast',
{ event: 'test' },
(payload) => messageReceived(payload)
)
.subscribe()
// Simple function to log any messages we receive
void messageReceived(payload) {
print(payload);
}
// Subscribe to the Channel
channelA
.onBroadcast(
event: 'test', callback: (payload) => messageReceived(payload))
.subscribe();
val channelA = clientA.channel("room-1")
//Listen for broadcast messages
val broadcastFlow: Flow<JsonObject> = channelA.broadcastFlow<JsonObject>("test")
.onEach {
println(it)
}
.launchIn(yourCoroutineScope) //you can also use .collect { } here
channelA.subscribe()
// Join a room/topic. Can be anything except for 'realtime'.
const channelB = clientA.channel('room-1')
channelB.subscribe((status) => {
// Wait for successful connection
if (status !== 'SUBSCRIBED') {
return null
}
// Send a message once the client is subscribed
channelB.send({
type: 'broadcast',
event: 'test',
payload: { message: 'hello, world' },
})
})
// Join a room/topic. Can be anything except for 'realtime'.
final channelB = supabase.channel('room-1');
channelB.subscribe((status, error) {
// Wait for successful connection
if (status != RealtimeSubscribeStatus.subscribed) {
return;
}
// Send a message once the client is subscribed
channelB.sendBroadcastMessage(
event: 'test',
payload: {'message': 'hello, world'},
);
});
val channelB = clientA.channel("room-1")
channelB.subscribe(blockUntilSubscribed = true) //You can also use the channelA.status flow instead, but this parameter will block the coroutine until the status is joined.
channelB.broadcast(
event = "test",
payload = YourMessage(message = "hello, world!")
)
val myChannel = supabase.channel("room-2") {
broadcast {
receiveOwnBroadcasts = true
}
}
val broadcastFlow: Flow<JsonObject> = myChannel.broadcastFlow<JsonObject>("test-my-messages")
.onEach {
println(it)
}
.launchIn(yourCoroutineScope)
myChannel.subscribe(blockUntilSubscribed = true) //You can also use the myChannel.status flow instead, but this parameter will block the coroutine until the status is joined.
myChannel.broadcast(
event = "test-my-messages",
payload = YourMessage(
message = "talking to myself"
)
)
val myChannel = supabase.channel("room-2") {
broadcast {
acknowledgeBroadcasts = true
}
}
myChannel.subscribe(blockUntilSubscribed = true) //You can also use the myChannel.status flow instead, but this parameter will block the coroutine until the status is joined.
myChannel.broadcast(event = "acknowledge", buildJsonObject { })
const channel = client.channel('test-channel')
// No need to subscribe to channel
channel
.send({
type: 'broadcast',
event: 'test',
payload: { message: 'Hi' },
})
.then((resp) => console.log(resp))
// Remember to clean up the channel
client.removeChannel(channel)
// No need to subscribe to channel
final channel = supabase.channel('test-channel');
final res = await channel.sendBroadcastMessage(
event: "test",
payload: {
'message': 'Hi',
},
);
print(res);
val myChannel = supabase.channel("room-2") {
broadcast {
acknowledgeBroadcasts = true
}
}
// No need to subscribe to channel
myChannel.broadcast(event = "test", buildJsonObject {
put("message", "Hi")
})