Skip to content
Merged
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
55 changes: 55 additions & 0 deletions src/web-capabilities.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,59 @@ describe('WebCapabilities', () => {
expect(WebCapabilities.isCapableOfReceiving1080pVideo()).toBe(CapabilityState.CAPABLE);
expect(WebCapabilities.isCapableOfSending1080pVideo()).toBe(CapabilityState.CAPABLE);
});
describe('supportsEncodedStreamTransforms', () => {
afterEach(() => {
// Clean up window modifications
delete (window as Window & { RTCRtpSender?: unknown }).RTCRtpSender;
});

it('should return CAPABLE when encoded transforms are supported', () => {
expect.assertions(1);

/**
* Mock RTCRtpSender constructor for testing.
*/
// eslint-disable-next-line @typescript-eslint/no-empty-function
const MockRTCRtpSender = function MockRTCRtpSender() {};
MockRTCRtpSender.prototype = {
transform: {},
};

Object.defineProperty(window, 'RTCRtpSender', {
writable: true,
configurable: true,
value: MockRTCRtpSender,
});

expect(WebCapabilities.supportsEncodedStreamTransforms()).toBe(CapabilityState.CAPABLE);
});

it('should return NOT_CAPABLE when RTCRtpSender is not available', () => {
expect.assertions(1);

// Ensure RTCRtpSender is not available
delete (window as Window & { RTCRtpSender?: unknown }).RTCRtpSender;

expect(WebCapabilities.supportsEncodedStreamTransforms()).toBe(CapabilityState.NOT_CAPABLE);
});

it('should return NOT_CAPABLE when transform is not in RTCRtpSender prototype', () => {
expect.assertions(1);

/**
* Mock RTCRtpSender constructor without transform property.
*/
// eslint-disable-next-line @typescript-eslint/no-empty-function
const MockRTCRtpSender = function MockRTCRtpSender() {};
MockRTCRtpSender.prototype = {};

Object.defineProperty(window, 'RTCRtpSender', {
writable: true,
configurable: true,
value: MockRTCRtpSender,
});

expect(WebCapabilities.supportsEncodedStreamTransforms()).toBe(CapabilityState.NOT_CAPABLE);
});
});
});
11 changes: 11 additions & 0 deletions src/web-capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,15 @@ export class WebCapabilities {
}
return CapabilityState.CAPABLE;
}

/**
* Checks whether the browser supports encoded stream transforms.
*
* @returns A {@link CapabilityState}.
*/
static supportsEncodedStreamTransforms(): CapabilityState {
return window.RTCRtpSender && 'transform' in RTCRtpSender.prototype
? CapabilityState.CAPABLE
: CapabilityState.NOT_CAPABLE;
}
}