-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support presence message extras #1418
Conversation
It's unfortunate to have the asymmetry of having |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the features spec, extras should be the second argument to enter
, leave
, update
, similarly it's supposed to be the final argument to enterClient
et al, is there a reason for breaking from the spec here?
A few reasons:
|
@lmars fair enough, i don't disagree with (1) and (2). As for supporting this without a breaking change we could support both signatures for enter(data: any): Promise<void>;
enter(presenceMessage: PresenceMessage): Promise<void>;
enter(dataOrPresenceMessage: any): Promise<void> {
if (dataOrPresenceMessage instanceof PresenceMessage) {
// normalise arguments
}
// ...
} i guess the only way this would be breaking would be if someone is already using a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also - any changes/additions to the public api need to be added to ably.d.ts
, so with the changes in their current state we would need to add the enterMessage
signature.
@owenpearson ah thanks, I wasn't aware you could do presence.enter(PresenceMessage.fromValues({
data,
extras: { headers: { key: 'value' } },
})); Given that |
Yeah I guess this means we can't add a new signature, would be good to update the docstrings to mention this though |
Signed-off-by: Lewis Marshall <[email protected]>
Signed-off-by: Lewis Marshall <[email protected]>
Done in 5baf94d. Comments addressed, PTAL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
* Initialises a `PresenceMessage` from a `PresenceMessage`-like object. | ||
* | ||
* @param values - The values to intialise the `PresenceMessage` from. | ||
* @param stringifyAction - Whether to convert the `action` field from a number to a string. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not be exposing things like a stringifyAction
param in the public api. There is no reason a user of the lib should have to know or care that we use numerical encoding in our internal wire protocol, and this doc string is meaningless to such a user.
I'm not a fan of having the one method to do conceptually quite different actions controlled by that param anyway, so in #1923 I've split it into two different methods, fromValues(values: Properties<PresenceMessage>): Message
suitable for public use, and fromWireProtocol(values: WireProtocolPresenceMessage): PresenceMessage
as an internal method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I didn't introduce the argument, I just needed the function to be included here to be able to call it from Spaces, I paid very little attention to whether or not the argument is suitable, what you suggest sounds good to me 👍
As per RTP8a and TP3i, presence messages support the extras field, but there is currently no way to set presence extras in the API (even though the IDL indicates the
enter
function signature asenter(Data?, extras?: JsonObject) => io
).Rather than making a breaking change to the
enter
function, this PR introduces anenterMessage
function which supports passing aPresenceMessage
, similar to howpublish
supports passing aMessage
, for example:This functionality is required for an upcoming release of the Spaces SDK.
MMB-212