@livepeer/core-web
Advanced tools
Comparing version 4.2.8 to 5.0.0
@@ -81,4 +81,31 @@ // src/broadcast.ts | ||
} | ||
function preferCodec(sdp, codec) { | ||
const lines = sdp.split("\r\n"); | ||
const mLineIndex = lines.findIndex((line) => line.startsWith("m=video")); | ||
if (mLineIndex === -1) return sdp; | ||
const codecRegex = new RegExp(`a=rtpmap:(\\d+) ${codec}(/\\d+)+`); | ||
const codecLine = lines.find((line) => codecRegex.test(line)); | ||
if (!codecLine) return sdp; | ||
const codecPayload = codecRegex.exec(codecLine)[1]; | ||
const mLineElements = lines[mLineIndex].split(" "); | ||
const reorderedMLine = [ | ||
...mLineElements.slice(0, 3), | ||
codecPayload, | ||
...mLineElements.slice(3).filter((payload) => payload !== codecPayload) | ||
]; | ||
lines[mLineIndex] = reorderedMLine.join(" "); | ||
return lines.join("\r\n"); | ||
} | ||
async function constructClientOffer(peerConnection, endpoint) { | ||
if (peerConnection && endpoint) { | ||
const originalCreateOffer = peerConnection.createOffer.bind(peerConnection); | ||
peerConnection.createOffer = async function(...args) { | ||
const originalOffer = await originalCreateOffer.apply(this, args); | ||
return new RTCSessionDescription({ | ||
// @ts-ignore (TODO: fix this) | ||
type: originalOffer.type, | ||
// @ts-ignore (TODO: fix this) | ||
sdp: preferCodec(originalOffer.sdp, "H264") | ||
}); | ||
}; | ||
const offer = await peerConnection.createOffer(); | ||
@@ -85,0 +112,0 @@ await peerConnection.setLocalDescription(offer); |
@@ -218,4 +218,31 @@ // src/media/controls/controller.ts | ||
} | ||
function preferCodec(sdp, codec) { | ||
const lines = sdp.split("\r\n"); | ||
const mLineIndex = lines.findIndex((line) => line.startsWith("m=video")); | ||
if (mLineIndex === -1) return sdp; | ||
const codecRegex = new RegExp(`a=rtpmap:(\\d+) ${codec}(/\\d+)+`); | ||
const codecLine = lines.find((line) => codecRegex.test(line)); | ||
if (!codecLine) return sdp; | ||
const codecPayload = codecRegex.exec(codecLine)[1]; | ||
const mLineElements = lines[mLineIndex].split(" "); | ||
const reorderedMLine = [ | ||
...mLineElements.slice(0, 3), | ||
codecPayload, | ||
...mLineElements.slice(3).filter((payload) => payload !== codecPayload) | ||
]; | ||
lines[mLineIndex] = reorderedMLine.join(" "); | ||
return lines.join("\r\n"); | ||
} | ||
async function constructClientOffer(peerConnection, endpoint) { | ||
if (peerConnection && endpoint) { | ||
const originalCreateOffer = peerConnection.createOffer.bind(peerConnection); | ||
peerConnection.createOffer = async function(...args) { | ||
const originalOffer = await originalCreateOffer.apply(this, args); | ||
return new RTCSessionDescription({ | ||
// @ts-ignore (TODO: fix this) | ||
type: originalOffer.type, | ||
// @ts-ignore (TODO: fix this) | ||
sdp: preferCodec(originalOffer.sdp, "H264") | ||
}); | ||
}; | ||
const offer = await peerConnection.createOffer(); | ||
@@ -222,0 +249,0 @@ await peerConnection.setLocalDescription(offer); |
@@ -59,4 +59,31 @@ // src/webrtc/shared.ts | ||
} | ||
function preferCodec(sdp, codec) { | ||
const lines = sdp.split("\r\n"); | ||
const mLineIndex = lines.findIndex((line) => line.startsWith("m=video")); | ||
if (mLineIndex === -1) return sdp; | ||
const codecRegex = new RegExp(`a=rtpmap:(\\d+) ${codec}(/\\d+)+`); | ||
const codecLine = lines.find((line) => codecRegex.test(line)); | ||
if (!codecLine) return sdp; | ||
const codecPayload = codecRegex.exec(codecLine)[1]; | ||
const mLineElements = lines[mLineIndex].split(" "); | ||
const reorderedMLine = [ | ||
...mLineElements.slice(0, 3), | ||
codecPayload, | ||
...mLineElements.slice(3).filter((payload) => payload !== codecPayload) | ||
]; | ||
lines[mLineIndex] = reorderedMLine.join(" "); | ||
return lines.join("\r\n"); | ||
} | ||
async function constructClientOffer(peerConnection, endpoint) { | ||
if (peerConnection && endpoint) { | ||
const originalCreateOffer = peerConnection.createOffer.bind(peerConnection); | ||
peerConnection.createOffer = async function(...args) { | ||
const originalOffer = await originalCreateOffer.apply(this, args); | ||
return new RTCSessionDescription({ | ||
// @ts-ignore (TODO: fix this) | ||
type: originalOffer.type, | ||
// @ts-ignore (TODO: fix this) | ||
sdp: preferCodec(originalOffer.sdp, "H264") | ||
}); | ||
}; | ||
const offer = await peerConnection.createOffer(); | ||
@@ -63,0 +90,0 @@ await peerConnection.setLocalDescription(offer); |
@@ -5,3 +5,3 @@ { | ||
"license": "MIT", | ||
"version": "4.2.8", | ||
"version": "5.0.0", | ||
"type": "module", | ||
@@ -8,0 +8,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
779128
6878