-
Notifications
You must be signed in to change notification settings - Fork 18
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
Conversation
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.
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).
src/media/local-stream.ts
Outdated
@@ -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. |
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.
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() { |
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.
nit: let's do toJson
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.
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
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.
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 { |
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.
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
.
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.
@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?
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.
@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).
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.
👍
yeah, good point, it would be good to include |
id: this.inputStream.id, | ||
muted: this.muted, | ||
label: this.label, | ||
enabled: this.inputTrack.enabled, |
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.
@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
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.
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).
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.
@marcin-bazyl please let me know what you think about Bryce's idea to remove the enabled state.
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.
for debugging purposes it's better to keep both muted
and enabled
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, 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,
...
},
...
}
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.
@brycetham updated recording your advice, thanks
@bbaldino @marcin-bazyl FYI
@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. |
src/media/local-stream.ts
Outdated
toJSON() { | ||
return { | ||
muted: this.muted, | ||
enabled: this.inputTrack.enabled, |
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.
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...
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.
@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, |
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.
...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
.
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.
@brycetham updated this part, thanks)
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.
Looks good to me 👍
Thanks, guys, for your review. Merge it 👍 |
# [2.4.0](v2.3.1...v2.4.0) (2024-01-29) ### Features * add custom method toJSON for _LocalStream ([#70](#70)) ([6ac5ba1](6ac5ba1))
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:
_LocalStream
object and add customtoJSON
method_LocalStream