Skip to content

Commit d697bdc

Browse files
committed
Code refactoring for #1644
1 parent ad2383d commit d697bdc

File tree

1 file changed

+6
-22
lines changed

1 file changed

+6
-22
lines changed

www/video-rtc.js

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -580,13 +580,14 @@ export class VideoRTC extends HTMLElement {
580580

581581
/** @type {MediaStream} */
582582
const stream = video2.srcObject;
583-
if (stream.getVideoTracks().length > 0) rtcPriority += 0x220;
583+
if (stream.getVideoTracks().length > 0) {
584+
// not the best, but a pretty simple way to check a codec
585+
const isH265Supported = this.pc.remoteDescription.sdp.includes('H265/90000');
586+
rtcPriority += isH265Supported ? 0x240 : 0x220;
587+
}
584588
if (stream.getAudioTracks().length > 0) rtcPriority += 0x102;
585589

586-
if (this.mseCodecs.indexOf('hvc1.')) {
587-
if (VideoRTC.isH265Supported()) rtcPriority += 0x230;
588-
else msePriority += 0x230;
589-
}
590+
if (this.mseCodecs.indexOf('hvc1.') >= 0) msePriority += 0x230;
590591
if (this.mseCodecs.indexOf('avc1.') >= 0) msePriority += 0x210;
591592
if (this.mseCodecs.indexOf('mp4a.') >= 0) msePriority += 0x101;
592593

@@ -667,23 +668,6 @@ export class VideoRTC extends HTMLElement {
667668
this.send({type: 'mp4', value: this.codecs(this.video.canPlayType)});
668669
}
669670

670-
static isH265Supported() {
671-
try {
672-
const videoCodecs = RTCRtpSender?.getCapabilities('video')?.codecs;
673-
674-
if (!videoCodecs) {
675-
return false;
676-
}
677-
678-
return videoCodecs.some(codec =>
679-
codec.mimeType.toLowerCase().includes('h265') ||
680-
codec.mimeType.toLowerCase().includes('hevc')
681-
);
682-
} catch {
683-
return false;
684-
}
685-
}
686-
687671
static btoa(buffer) {
688672
const bytes = new Uint8Array(buffer);
689673
const len = bytes.byteLength;

0 commit comments

Comments
 (0)