Skip to content

Commit

Permalink
Make parse sdp lines separated to \r\n
Browse files Browse the repository at this point in the history
  • Loading branch information
SangwonOh committed Dec 13, 2021
1 parent 2d64b13 commit 17e7387
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/OvenLiveKit.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function checkIOSVersion() {

function getFormatNumber(sdp, format) {

const lines = sdp.split('\n');
const lines = sdp.split('\r\n');
let formatNumber = -1;

for (let i = 0; i < lines.length - 1; i++) {
Expand All @@ -63,7 +63,7 @@ function getFormatNumber(sdp, format) {

function removeFormat(sdp, formatNumber) {
let newLines = [];
let lines = sdp.split('\n');
let lines = sdp.split('\r\n');

for (let i = 0; i < lines.length; i++) {

Expand All @@ -76,7 +76,7 @@ function removeFormat(sdp, formatNumber) {
}
}

return newLines.join('\n')
return newLines.join('\r\n')
}

async function getStreamForDeviceCheck() {
Expand Down Expand Up @@ -266,7 +266,7 @@ function addMethod(instance) {
// From https://webrtchacks.com/limit-webrtc-bandwidth-sdp/
function setBitrateLimit(sdp, media, bitrate) {

let lines = sdp.split('\n');
let lines = sdp.split('\r\n');
let line = -1;

for (let i = 0; i < lines.length; i++) {
Expand Down Expand Up @@ -294,7 +294,7 @@ function addMethod(instance) {

lines[line] = 'b=AS:' + bitrate;

return lines.join('\n');
return lines.join('\r\n');
}

// Add a new b line
Expand All @@ -303,7 +303,7 @@ function addMethod(instance) {
newLines.push('b=AS:' + bitrate)
newLines = newLines.concat(lines.slice(line, lines.length))

return newLines.join('\n')
return newLines.join('\r\n')
}

function initWebSocket(connectionUrl) {
Expand Down Expand Up @@ -381,7 +381,7 @@ function addMethod(instance) {

const fmtpStr = instance.connectionConfig.sdp.appendFmtp;

const lines = sdp.split('\n');
const lines = sdp.split('\r\n');
const payloads = [];

for (let i = 0; i < lines.length; i++) {
Expand All @@ -392,7 +392,7 @@ function addMethod(instance) {

for (let j = 3; j < tokens.length; j++) {

payloads.push(tokens[j].replace('\r', ''));
payloads.push(tokens[j]);
}

break;
Expand All @@ -417,13 +417,13 @@ function addMethod(instance) {

if (lines[j].indexOf('a=rtpmap:' + payloads[i]) === 0) {

lines[j] += '\na=fmtp:' + payloads[i] + ' ' + fmtpStr;
lines[j] += '\r\na=fmtp:' + payloads[i] + ' ' + fmtpStr;
}
}
}
}

return lines.join('\n')
return lines.join('\r\n')
}

function createPeerConnection(id, peerId, offer, candidates, iceServers) {
Expand Down Expand Up @@ -558,6 +558,9 @@ function addMethod(instance) {
peerConnection.createAnswer()
.then(function (answer) {

console.log(logHeader, 'Answer')
console.log(answer.sdp)

if (checkIOSVersion() >= 15) {

const formatNumber = getFormatNumber(answer.sdp, 'H264');
Expand Down

0 comments on commit 17e7387

Please sign in to comment.