Skip to content
This repository has been archived by the owner on Jul 20, 2024. It is now read-only.

Commit

Permalink
Fix limiter undefined (#45)
Browse files Browse the repository at this point in the history
* fix: stream view limiter not working

* update simulcast example
  • Loading branch information
luongngocminh authored Jan 2, 2024
1 parent 2f3c315 commit 84cd50f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion samples/simulcast/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async function boot() {
document.getElementById('quality').onchange = (event) => {
let layers = event.target.value.split('-');
let element = document.getElementById('my_video');
element.receiver.limit(50, 0, 0, parseInt(layers[0]), parseInt(layers[1]));
element.receiver.limit({ priority: 50, maxSpatial: parseInt(layers[0]), maxTemporal: parseInt(layers[1]) });
};
}

Expand Down
26 changes: 14 additions & 12 deletions src/lib/consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ export class StreamConsumer extends TypedEventEmitter<IConsumerCallbacks> {
key: string,
limit: StreamLimit = { priority: 50, maxSpatial: 2, minSpatial: 0, maxTemporal: 2, minTemporal: 0 },
): MediaStream {
const { priority, maxSpatial, maxTemporal, minSpatial, minTemporal } = limit;
this.keys.set(key, {
priority,
maxSpatial,
maxTemporal,
minSpatial: minSpatial || 0,
minTemporal: minTemporal || 0,
priority: limit?.priority,
maxSpatial: limit?.maxSpatial,
maxTemporal: limit?.maxTemporal,
minSpatial: limit?.minSpatial || 0,
minTemporal: limit?.minTemporal || 0,
});
if (!this.receiver) {
this.receiver = this._session.takeReceiver(this._remote.kind);
Expand All @@ -53,7 +52,7 @@ export class StreamConsumer extends TypedEventEmitter<IConsumerCallbacks> {
this.receiver.on('track_added', this.onAddTrack);
this.receiver.on('quality', this.onQuality);

this.receiver.switch(this._remote, priority);
this.receiver.switch(this._remote, limit?.priority);
}
this.configLayer();
return this.receiver.stream;
Expand All @@ -64,11 +63,14 @@ export class StreamConsumer extends TypedEventEmitter<IConsumerCallbacks> {
* @param key - The key of the view to set the limit for.
* @param limit - The limit to set for the view.
*/
public limit(
key: string,
{ priority = 50, maxSpatial = 2, minSpatial = 0, maxTemporal = 2, minTemporal = 0 }: StreamLimit,
) {
this.keys.set(key, { priority, maxSpatial, maxTemporal, minSpatial, minTemporal });
public limit(key: string, limit: StreamLimit) {
this.keys.set(key, {
priority: limit?.priority || 50,
maxSpatial: limit?.maxSpatial || 2,
maxTemporal: limit?.maxTemporal || 2,
minSpatial: limit?.minSpatial || 0,
minTemporal: limit?.minTemporal || 0,
});
this.configLayer();
}

Expand Down

0 comments on commit 84cd50f

Please sign in to comment.