Skip to content

Commit

Permalink
Add RealtimeChannel.sendState and mark STATE messages as those that…
Browse files Browse the repository at this point in the history
… require an ACK
  • Loading branch information
VeskeR committed Jan 15, 2025
1 parent 195e67a commit 5b365bc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/common/lib/client/realtimechannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,17 @@ class RealtimeChannel extends EventEmitter {
this.sendMessage(msg, callback);
}

sendState(state: StateMessage[]): Promise<void> {
return new Promise((resolve, reject) => {
const msg = protocolMessageFromValues({
action: actions.STATE,
channel: this.name,
state,
});
this.sendMessage(msg, (err) => (err ? reject(err) : resolve()));
});
}

// Access to this method is synchronised by ConnectionManager#processChannelMessage, in order to synchronise access to the state stored in _decodingContext.
async processMessage(message: ProtocolMessage): Promise<void> {
if (
Expand Down
3 changes: 2 additions & 1 deletion src/common/lib/transport/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export class PendingMessage {
this.merged = false;
const action = message.action;
this.sendAttempted = false;
this.ackRequired = action == actions.MESSAGE || action == actions.PRESENCE;
this.ackRequired =
typeof action === 'number' && [actions.MESSAGE, actions.PRESENCE, actions.STATE].includes(action);
}
}

Expand Down

0 comments on commit 5b365bc

Please sign in to comment.