Skip to content

[FOR TESTING] Add consumer.degrade()#1546

Draft
ibc wants to merge 8 commits intov3from
debug-apply-delay-and-loss-to-consumer
Draft

[FOR TESTING] Add consumer.degrade()#1546
ibc wants to merge 8 commits intov3from
debug-apply-delay-and-loss-to-consumer

Conversation

@ibc
Copy link
Copy Markdown
Member

@ibc ibc commented Jun 18, 2025

Details

In Consumer.ts:

/**
 * Degrade RTP transmission.
 * - durationMs: Duration that the degradation will take.
 * - maxDelayMs: Max delay (in ms) to be applied to each packet.
 * - delayPercent: Only apply delay to this percent of the packets.
 * - lossPercent: Generate packet loss by given percent value.
 *
 * @remarks
 * - Only implemented in `SimpleConsumer`.
 * - After `durationMs`, or if `consumer.degrade()` is called again with
 *   `durationMs: 0`, then degradation is immediately stopped and all delayed
 *   buffered packets are immediately sent (all together).
 *
 * @throws
 * - If called on a non `SimpleConsumer` (due to method not implemented).
 *
 * @example
 * ```ts
 * consumer.degrade({
 *   durationMs: 10000
 *   maxDelayMs: 3000,
 *   delayPercent: 20,
 *   lossPercent: 0,
 * });
 * ```
 */
degrade({
	durationMs,
	maxDelayMs,
	delayPercent,
	lossPercent,
}: {
	durationMs?: number;
	maxDelayMs?: number;
	delayPercent?: number;
	lossPercent?: number;
}): Promise<void>;

Usage example in the mediasoup-demo

--- a/server/lib/Room.js
+++ b/server/lib/Room.js
@@ -1752,6 +1752,17 @@ class Room extends EventEmitter
 								paused          : true,
 								ignoreDtx       : true
 							});
+
+						// TODO: Testing degradation.
+						if (consumer.kind === 'video')
+						{
+							consumer.degrade({
+								durationMs: 5000,
+								maxDelayMs: 3000,
+								delayPercent: 50,
+								lossPercent: 0,
+							});
+						}
 					}
 					catch (error)
 					{

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant