@baasix/sdk 0.1.9 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +28 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +41 -12
- package/dist/index.d.ts +41 -12
- package/dist/index.js +28 -15
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3701,21 +3701,26 @@ var RealtimeModule = class {
|
|
|
3701
3701
|
* will be visible to all other members via {@link getRoomMembers} and in
|
|
3702
3702
|
* `room:user:joined` events.
|
|
3703
3703
|
*
|
|
3704
|
+
* Returns the room's message history (up to 200 messages) so late joiners
|
|
3705
|
+
* can replay past messages immediately.
|
|
3706
|
+
*
|
|
3704
3707
|
* @param roomName - The room to join.
|
|
3705
3708
|
* @param metadata - Optional key/value pairs stored alongside this member.
|
|
3709
|
+
* @returns An object containing the buffered `history` for the room.
|
|
3706
3710
|
*
|
|
3707
3711
|
* @example
|
|
3708
3712
|
* ```typescript
|
|
3709
|
-
*
|
|
3710
|
-
* await baasix.realtime.joinRoom('game:lobby', {
|
|
3713
|
+
* const { history } = await baasix.realtime.joinRoom('game:lobby', {
|
|
3711
3714
|
* username: 'Alice',
|
|
3712
3715
|
* avatar: 'https://example.com/alice.png',
|
|
3713
|
-
* team: 'blue',
|
|
3714
3716
|
* });
|
|
3715
3717
|
*
|
|
3716
|
-
* //
|
|
3717
|
-
*
|
|
3718
|
-
*
|
|
3718
|
+
* // Render past messages first
|
|
3719
|
+
* history.forEach((msg) => renderMessage(msg));
|
|
3720
|
+
*
|
|
3721
|
+
* // Then listen for new ones
|
|
3722
|
+
* baasix.realtime.onRoomMessage('game:lobby', 'chat', (data) => {
|
|
3723
|
+
* renderMessage(data);
|
|
3719
3724
|
* });
|
|
3720
3725
|
* ```
|
|
3721
3726
|
*/
|
|
@@ -3727,7 +3732,7 @@ var RealtimeModule = class {
|
|
|
3727
3732
|
this.socket.emit("room:join", { room: roomName, metadata }, (response) => {
|
|
3728
3733
|
if (response.status === "success") {
|
|
3729
3734
|
this.setupRoomListeners(roomName);
|
|
3730
|
-
resolve();
|
|
3735
|
+
resolve({ history: response.history ?? [] });
|
|
3731
3736
|
} else {
|
|
3732
3737
|
reject(new Error(response.message || "Failed to join room"));
|
|
3733
3738
|
}
|
|
@@ -3865,25 +3870,33 @@ var RealtimeModule = class {
|
|
|
3865
3870
|
};
|
|
3866
3871
|
}
|
|
3867
3872
|
/**
|
|
3868
|
-
* Send a message to a room
|
|
3869
|
-
*
|
|
3873
|
+
* Send a message to a room.
|
|
3874
|
+
*
|
|
3875
|
+
* By default the message is stored in the room's history buffer so late
|
|
3876
|
+
* joiners can replay it. Pass `{ history: false }` to broadcast without
|
|
3877
|
+
* persisting (e.g. ephemeral cursor positions, typing indicators).
|
|
3878
|
+
*
|
|
3870
3879
|
* @example
|
|
3871
3880
|
* ```typescript
|
|
3872
|
-
* //
|
|
3881
|
+
* // Persisted — replayed to future joiners
|
|
3873
3882
|
* await baasix.realtime.sendToRoom('game:lobby', 'chat', { text: 'Hello!' });
|
|
3874
|
-
*
|
|
3875
|
-
* //
|
|
3876
|
-
* await baasix.realtime.sendToRoom('game:
|
|
3883
|
+
*
|
|
3884
|
+
* // Ephemeral — broadcast only, never stored in history
|
|
3885
|
+
* await baasix.realtime.sendToRoom('game:lobby', 'typing', { userId }, { history: false });
|
|
3886
|
+
*
|
|
3887
|
+
* // Game move — skips history
|
|
3888
|
+
* await baasix.realtime.sendToRoom('game:123', 'move', { x: 10, y: 20 }, { history: false });
|
|
3877
3889
|
* ```
|
|
3878
3890
|
*/
|
|
3879
|
-
async sendToRoom(roomName, event, payload) {
|
|
3891
|
+
async sendToRoom(roomName, event, payload, options = {}) {
|
|
3880
3892
|
if (!this.socket?.connected) {
|
|
3881
3893
|
throw new Error("Not connected. Call connect() first.");
|
|
3882
3894
|
}
|
|
3895
|
+
const history = options.history ?? true;
|
|
3883
3896
|
return new Promise((resolve, reject) => {
|
|
3884
3897
|
this.socket.emit(
|
|
3885
3898
|
"room:message",
|
|
3886
|
-
{ room: roomName, event, payload },
|
|
3899
|
+
{ room: roomName, event, payload, history },
|
|
3887
3900
|
(response) => {
|
|
3888
3901
|
if (response.status === "success") {
|
|
3889
3902
|
resolve();
|