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

Allow setting RtpEncodingParameters for individual encodings #173

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Producer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export declare class Producer extends EnhancedEventEmitter {
/**
* Sets the DSCP value.
*/
setRtpEncodingParameters(params: RTCRtpEncodingParameters): Promise<void>;
setRtpEncodingParameters(params: RTCRtpEncodingParameters, idx?: number): Promise<void>;
private _onTrackEnded;
private _handleTrack;
private _destroyTrack;
Expand Down
2 changes: 1 addition & 1 deletion lib/Producer.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/Producer.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,12 @@ class Producer extends EnhancedEventEmitter_1.EnhancedEventEmitter {
/**
* Sets the DSCP value.
*/
async setRtpEncodingParameters(params) {
async setRtpEncodingParameters(params, idx) {
if (this._closed)
throw new errors_1.InvalidStateError('closed');
else if (typeof params !== 'object')
throw new TypeError('invalid params');
await this.safeEmitAsPromise('@setrtpencodingparameters', params);
await this.safeEmitAsPromise('@setrtpencodingparameters', params, idx);
}
_onTrackEnded() {
logger.debug('track "ended" event');
Expand Down
4 changes: 2 additions & 2 deletions lib/Transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,8 @@ class Transport extends EnhancedEventEmitter_1.EnhancedEventEmitter {
.then(callback)
.catch(errback);
});
producer.on('@setrtpencodingparameters', (params, callback, errback) => {
this._awaitQueue.push(async () => (this._handler.setRtpEncodingParameters(producer.localId, params)), 'producer @setrtpencodingparameters event')
producer.on('@setrtpencodingparameters', (params, idx, callback, errback) => {
this._awaitQueue.push(async () => (this._handler.setRtpEncodingParameters(producer.localId, params, idx)), 'producer @setrtpencodingparameters event')
.then(callback)
.catch(errback);
});
Expand Down
2 changes: 1 addition & 1 deletion lib/handlers/Chrome55.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export declare class Chrome55 extends HandlerInterface {
stopSending(localId: string): Promise<void>;
replaceTrack(localId: string, track: MediaStreamTrack | null): Promise<void>;
setMaxSpatialLayer(localId: string, spatialLayer: number): Promise<void>;
setRtpEncodingParameters(localId: string, params: any): Promise<void>;
setRtpEncodingParameters(localId: string, params: any, idx?: number): Promise<void>;
getSenderStats(localId: string): Promise<RTCStatsReport>;
sendDataChannel({ ordered, maxPacketLifeTime, maxRetransmits, label, protocol }: HandlerSendDataChannelOptions): Promise<HandlerSendDataChannelResult>;
receive({ trackId, kind, rtpParameters }: HandlerReceiveOptions): Promise<HandlerReceiveResult>;
Expand Down
2 changes: 1 addition & 1 deletion lib/handlers/Chrome55.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/handlers/Chrome55.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ class Chrome55 extends HandlerInterface_1.HandlerInterface {
throw new errors_1.UnsupportedError(' not implemented');
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async setRtpEncodingParameters(localId, params) {
async setRtpEncodingParameters(localId, params, idx) {
throw new errors_1.UnsupportedError('not supported');
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down
2 changes: 1 addition & 1 deletion lib/handlers/Chrome67.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export declare class Chrome67 extends HandlerInterface {
stopSending(localId: string): Promise<void>;
replaceTrack(localId: string, track: MediaStreamTrack | null): Promise<void>;
setMaxSpatialLayer(localId: string, spatialLayer: number): Promise<void>;
setRtpEncodingParameters(localId: string, params: any): Promise<void>;
setRtpEncodingParameters(localId: string, params: any, idx?: number): Promise<void>;
getSenderStats(localId: string): Promise<RTCStatsReport>;
sendDataChannel({ ordered, maxPacketLifeTime, maxRetransmits, label, protocol }: HandlerSendDataChannelOptions): Promise<HandlerSendDataChannelResult>;
receive({ trackId, kind, rtpParameters }: HandlerReceiveOptions): Promise<HandlerReceiveResult>;
Expand Down
2 changes: 1 addition & 1 deletion lib/handlers/Chrome67.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions lib/handlers/Chrome67.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,16 +322,21 @@ class Chrome67 extends HandlerInterface_1.HandlerInterface {
});
await rtpSender.setParameters(parameters);
}
async setRtpEncodingParameters(localId, params) {
async setRtpEncodingParameters(localId, params, idx) {
this._assertSendDirection();
logger.debug('setRtpEncodingParameters() [localId:%s, params:%o]', localId, params);
const rtpSender = this._mapSendLocalIdRtpSender.get(localId);
if (!rtpSender)
throw new Error('associated RTCRtpSender not found');
const parameters = rtpSender.getParameters();
parameters.encodings.forEach((encoding, idx) => {
parameters.encodings[idx] = Object.assign(Object.assign({}, encoding), params);
});
if (idx == null) {
parameters.encodings.forEach((encoding, idx) => {
parameters.encodings[idx] = Object.assign(Object.assign({}, encoding), params);
});
}
else {
parameters.encodings[idx] = Object.assign(Object.assign({}, parameters.encodings[idx]), params);
}
await rtpSender.setParameters(parameters);
}
async getSenderStats(localId) {
Expand Down
Loading