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: update effects APIs #68

Merged
merged 2 commits into from
Jan 10, 2024
Merged

feat: update effects APIs #68

merged 2 commits into from
Jan 10, 2024

Conversation

brycetham
Copy link
Contributor

@brycetham brycetham commented Jan 8, 2024

This PR makes API changes to the LocalStream class regarding effects. The main change is eliminating the need to pass a name param to the addEffect method, since the effect object has its own identifiers as of https://github.com/webex/web-media-effects/pull/59.

The following APIs have been added:

  • getEffectById
  • getEffectByKind

The following API has been removed:

  • getEffect

The following API has been renamed:

  • getAllEffects -> getEffects (I think this new name makes sense with the new APIs; it matches the built-in MediaStream APIs, which have getTracks and getTrackById, for example)

@brycetham brycetham requested review from arun3528 and bbaldino January 8, 2024 17:07
const outputTrack = await effect.load(this.outputTrack);
async addEffect(effect: TrackEffect): Promise<void> {
// Check if the effect has already been added.
if (this.effects.includes(effect)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does this end up using to compare equality?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It just checks to see if the instances match, but I do think explicitly comparing id or kind would be better, so I can make that change.

Comment on lines +162 to +165
// After loading, check whether or not we still want to use this effect. If another effect of
// the same kind was added while this effect was loading, we only want to use the latest effect,
// so dispose this one. If the effects list was cleared while this effect was loading, also
// dispose it.
Copy link
Collaborator

Choose a reason for hiding this comment

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

It feels a bit strange that we'll allow overriding an affect of the same type that was added previously if it didn't finish loading yet, but we error on adding an effect of the same type after it's been loaded. I think I'd expect that subsequent additions of the same type of effect (without removing the previous one) should either always work or always fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The previous behavior was to override the effect if it didn't finish loading, so I think we should keep that behavior (since the client does depend on it). We didn't handle adding a duplicate effect after it has loaded previously, so I can change it so that it will also override instead of error.

* @param kind - The kind of the effects you want to get.
* @returns A list of effects.
*/
getEffectsByKind(kind: string): TrackEffect[] {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This returning an array seems inconsistent with the fact that we only allow one instance of each effect type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, will change it.

Copy link
Contributor

Choose a reason for hiding this comment

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

just curious , if we knew there is only 3 kind of effects why didn't we have some function like addVirtualBackgroundEffect rather have names passed in to the effects ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Well there are 3 effects now, but we want to support any kind of effect in the future as opposed to hard-coding the current ones in.

WebrtcCoreErrorType.ADD_EFFECT_FAILED,
`Effect ${effect.id} has already been added to this stream.`
);
if (this.effects.some((e) => e.id === effect.id)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

So this now checks if the same effect instance is being added, but I think we need to check for an existing effect of the same kind to replace it with this one?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, I didn't notice that all the code below is in this same method, I see there's handling there for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's logic starting at line 205 that handles this case.

@brycetham brycetham merged commit 64ac8b6 into main Jan 10, 2024
1 check passed
@brycetham brycetham deleted the btham/effects_changes branch January 10, 2024 20:25
bbaldino pushed a commit that referenced this pull request Jan 10, 2024
# [2.3.0](v2.2.3...v2.3.0) (2024-01-10)

### Features

* update effects APIs ([#68](#68)) ([64ac8b6](64ac8b6))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants