JavaScript: send

Sends a message into the channel.

Parameters

Examples

Send a message via websocket

const channel = supabase.channel('room1')

channel.subscribe((status) => {
  if (status === 'SUBSCRIBED') {
    channel.send({
      type: 'broadcast',
      event: 'cursor-pos',
      payload: { x: Math.random(), y: Math.random() },
    })
  }
})

Send a message via REST

const channel = supabase.channel('room1')

try {
  await channel.httpSend('cursor-pos', { x: Math.random(), y: Math.random() })
} finally {
  await supabase.removeChannel(channel)
}