> For the complete documentation index, see [llms.txt](https://dnotifier.gitbook.io/product-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dnotifier.gitbook.io/product-docs/realtime-communication/multiple-receivers/javascript-typescript.md). Agents can also search and read this documentation through its [MCP server](https://dnotifier.gitbook.io/product-docs/~gitbook/mcp).

# JavaScript / TypeScript

Send one payload to several recipients with `receiverIds`.

***

## Basic example

```js
import WebSocket from "ws";
import { DNotifier } from "@dnotifier-realtime/dnotifier";

const notifier = new DNotifier({
  appId: process.env.DNOTIFIER_APP_ID,
  secret: process.env.DNOTIFIER_SECRET,
  transport: "ws",
  userId: "user-alice",
  WebSocketImpl: WebSocket,
  onConnected: () => {},
  onMessage: (msg) => console.log(msg.payload.toJSON()),
  onDisconnected: () => {},
});

await notifier.connect();

await notifier.send({
  senderId: "user-alice",
  receiverIds: ["user-bob", "user-carol", "user-dave"],
  data: {
    type: "text",
    text: "Hello everyone",
  },
});
```

***

## Team notification pattern

```js
const teamMemberIds = ["employee-101", "employee-102", "employee-103"];

await notifier.send({
  senderId: "svc-notifications",
  receiverIds: teamMemberIds,
  data: {
    type: "notification",
    title: "Deploy complete",
    body: "v2.4.0 is live in production.",
  },
  saveHistory: false,
});
```

***

## Dynamic member list

```js
async function broadcastToRoom(roomId, payload) {
  const members = await loadRoomMembersFromYourDb(roomId);
  const receiverIds = members.map((m) => m.userId);

  await notifier.send({
    senderId: currentUserId,
    receiverIds,
    data: payload,
  });
}
```

Your app owns room membership, moderation, and access control.

***

## `sendBinary` with multiple receivers

```js
notifier.sendBinary({
  senderId: "user-alice",
  receiverIds: ["user-bob", "user-carol"],
  buffer: new Uint8Array([0x00, 0x01, 0x02]),
  type: "binary",
});
```

***

## Troubleshooting

| Issue                                | Check                                                     |
| ------------------------------------ | --------------------------------------------------------- |
| Only some recipients receive         | Offline users won't get live delivery                     |
| `receiverId or receiverIds required` | Pass `receiverIds` as a non-empty array                   |
| Wrong recipients                     | Verify your member list matches DNotifier `userId` values |

***

## Learn more

* [Send & receive text](https://dnotifier.gitbook.io/product-docs/realtime-communication/send-and-receive/javascript-typescript.md)
* [Binary messaging](https://dnotifier.gitbook.io/product-docs/realtime-communication/binary-messaging/javascript-typescript.md)
