Excluding event recipients
If a client applies a change optimistically before your server publishes it, receiving the same event can apply the change twice. This can cause a flicker or duplicate item.
Pass the acting client's connection ID to deliver the event to every other subscribed connection.
await bird.realtime.publish(appId, {
event: "message.created",
channels: ["presence-room-1"],
data: { body: "hello" },
exclude_connection_id: "26896.319537",
});client.realtime.publish(
app_id,
event="message.created",
channels=["presence-room-1"],
data={"body": "hello"},
exclude_connection_id="26896.319537",
)_, err := client.Realtime.Publish(context.Background(), appID, bird.RealtimePublishParams{
Event: "message.created",
Channels: []string{"presence-room-1"},
Data: map[string]any{"body": "hello"},
ExcludeConnectionID: "26896.319537",
})$bird->realtime->publish($appId, (new RealtimePublish())
->setEvent('message.created')
->setChannels(['presence-room-1'])
->setData(['body' => 'hello'])
->setExcludeConnectionId('26896.319537'));Get the connection ID
The client reads its connection ID and sends it with the request that triggers the change:
const bird = new BirdRealtime({ appKey: "your-app-key", region: "us1" });
await fetch("/messages", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({
body: "hello",
connection_id: bird.connection.connectionId,
}),
});let bird = BirdRealtime(options: .init(appKey: "your-app-key", region: "us1"))
var request = URLRequest(url: URL(string: "https://your-backend.example.com/messages")!)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "content-type")
request.httpBody = try JSONSerialization.data(withJSONObject: [
"body": "hello",
"connection_id": bird.connectionId ?? "",
])
_ = try await URLSession.shared.data(for: request)val bird = BirdRealtime(BirdRealtimeOptions(appKey = "your-app-key", region = "us1"))
// Send the client ID with the HTTP client your app already uses.
api.postMessage(body = "hello", connectionId = bird.connectionId)The ID is null until the connection is established and changes after a reconnect. Read bird.connection.connectionId in the browser or bird.connectionId in Swift and Kotlin when you make the request.
Pass the value to exclude_connection_id after validating it as untrusted request data. This field can suppress delivery to one connection but cannot grant access to an event.
Excluded connection behavior
Only the named connection is excluded. The same person's other tabs use separate connections and still receive the event.
Excluding a connection ID that is not subscribed, or no longer exists, is not an error. The publish delivers normally to everyone else.
When to omit exclusion
Use exclusion for optimistic interfaces. If the client waits for the event before applying a change, do not exclude it. Otherwise, the acting tab remains stale.
Next steps
- Publishing events covers the rest of the publish payload, including batching and broadcasting.
- Presence channels explain why one member can hold several connections.
- Publish an event is the full reference for the request.