Skip to content
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

feat: add custom method toJSON for _LocalStream #70

Merged
merged 5 commits into from
Jan 29, 2024

Conversation

antsukanova
Copy link
Contributor

The main purpose of this update is to make better work with LocalStream and smoother debugging for webex-js-sdk. Mainly it should get rid of custom overrides for objects and give more useful information in better structure. See current overrides here webex/webex-js-sdk@4089648

This PR consists of the following updates:

  • update for _LocalStream object and add custom toJSON method
  • added new test cases for _LocalStream

Copy link
Contributor

@brycetham brycetham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks fine, but I'll defer to @marcin-bazyl to see if the output of the toJSON function matches his expectations. I noticed the current workaround in the SDK includes label, readyState, and enabled (though I'd argue we should use muted instead for the last one).

@@ -283,6 +283,32 @@ abstract class _LocalStream extends Stream {
return this.effects;
}

/**
* Method to serialize data about input, output streams
* and also effects from _LocalStream.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to remove the "_" from your comments. Users of webrtc-core will only ever see LocalStream, never _LocalStream.

*
* @returns - A JSON-compatible object representation with data from _LocalStream.
*/
toJSON() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: let's do toJson

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toJson won't work, it has to be toJSON, because that's what JSON.stringify() calls, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry didn't realize this was an automatic hook for JSON.stringify. 👍

* @returns - A JSON-compatible object representation with data from _LocalStream.
*/
toJSON() {
return {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe another nitpick, but this is returning an objec, not "json", right? I think if this method is going to be called toJson we should JSON.stringify and return a String.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bbaldino yes and with your idea, it requires you to manually call your custom method each time you need it, and it won't be used automatically by JSON.stringify(). That's more transparent. But I also want to ask @marcin-bazyl will it be convenient to use it in this way?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bbaldino the whole point of this jira is to make JSON.stringify() work, not to invent new methods. Any library/component that uses webrtc-core should be free to call JSON.stringify() on instances of webrtc-core classes like LocalStream and that should not cause the browser to hang up (that's what's currently happening).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@marcin-bazyl
Copy link
Collaborator

Code looks fine, but I'll defer to @marcin-bazyl to see if the output of the toJSON function matches his expectations. I noticed the current workaround in the SDK includes label, readyState, and enabled (though I'd argue we should use muted instead for the last one).

yeah, good point, it would be good to include label, readyState, enabled and muted from the inputTrack

id: this.inputStream.id,
muted: this.muted,
label: this.label,
enabled: this.inputTrack.enabled,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bbaldino @brycetham not sure that for one case here it is useful to have a getter for enabled. So right now put it via inputTrack. Let me know if you have any other thoughts

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I wouldn't add a getter for enabled unless there is a need for it outside this function. Actually, I would argue that we shouldn't include enabled here at all, since muted already takes enabled into account.

I would also probably move muted, label, and readyState out of inputStream and put it at the same level as inputStream, outputStream, and effects. These things, in my opinion, apply to the whole LocalStream, not just the input (hence why we have explicitly defined getters for all of them).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcin-bazyl please let me know what you think about Bryce's idea to remove the enabled state.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for debugging purposes it's better to keep both muted and enabled

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, but let's keep it separate from the overall LocalStream mute state. So I would suggest something like this:

{
  muted: this.muted,
  inputStream: {
    muted: this.inputTrack.muted,
    enabled: this.inputTrack.enabled,
    ...
  },
  ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brycetham updated recording your advice, thanks
@bbaldino @marcin-bazyl FYI

@antsukanova
Copy link
Contributor Author

@marcin-bazyl @bbaldino @brycetham here is an example from the console of how it looks like for the test-app. Please let me know @marcin-bazyl if it is what you need.
Screenshot 2024-01-25 at 13 40 18

toJSON() {
return {
muted: this.muted,
enabled: this.inputTrack.enabled,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry if I wasn't clear in my previous comment. I meant let's keep enabled in inputStream and also have a separate muted property in inputStream as well. So, let's remove enabled here...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brycetham I understand your idea now. It sounds logical. Thank you for clarifying it for me. Will update

readyState: this.readyState,
inputStream: {
active: this.inputStream.active,
id: this.inputStream.id,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...and add enabled: this.inputTrack.enabled and muted: this.inputTrack.muted here. This way, we can tell the enabled and muted state of the input track apart from the overall muted state of the LocalStream.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brycetham updated this part, thanks)

@antsukanova antsukanova requested a review from brycetham January 26, 2024 15:27
Copy link
Contributor

@brycetham brycetham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 👍

@antsukanova
Copy link
Contributor Author

Thanks, guys, for your review. Merge it 👍

@antsukanova antsukanova merged commit 6ac5ba1 into main Jan 29, 2024
1 check passed
@antsukanova antsukanova deleted the antsukan/SPARK-467164 branch January 29, 2024 09:49
@antsukanova antsukanova self-assigned this Jan 29, 2024
@antsukanova antsukanova added the enhancement New feature or request label Jan 29, 2024
bbaldino pushed a commit that referenced this pull request Jan 29, 2024
# [2.4.0](v2.3.1...v2.4.0) (2024-01-29)

### Features

* add custom method toJSON for _LocalStream ([#70](#70)) ([6ac5ba1](6ac5ba1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants