diff --git a/package.json b/package.json index d9efff6..7507460 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "@types/react-redux": "^7.1.5", "@types/reactstrap": "^8.4.2", "@types/redux-persist": "^4.3.1", + "@types/sdp-transform": "^2.4.3", "@types/wavesurfer.js": "^3.2.0", "@types/webpack-env": "^1.14.1", "@typescript-eslint/eslint-plugin": "^2.2.0", @@ -83,6 +84,7 @@ "resolve": "1.12.0", "resolve-url-loader": "3.1.0", "sass-loader": "7.2.0", + "sdp-transform": "^2.14.0", "semver": "6.3.0", "style-loader": "1.0.0", "terser-webpack-plugin": "1.4.1", diff --git a/src/broadcast/rtc_streamer.ts b/src/broadcast/rtc_streamer.ts index 9793fd2..d2316cd 100644 --- a/src/broadcast/rtc_streamer.ts +++ b/src/broadcast/rtc_streamer.ts @@ -1,3 +1,5 @@ +import SdpTransform from "sdp-transform"; + import { Streamer, ConnectionStateListener, @@ -70,7 +72,24 @@ export class WebRTCStreamer extends Streamer { this.ws!.close(); } const offer = await this.pc.createOffer(); - // TODO do some fun SDP fuckery to get quality + + // Do some fun SDP fuckery to get better quality + const parsed = SdpTransform.parse(offer.sdp!); + console.log("Old SDP", parsed); + parsed.media.forEach(track => { + let opusIndex = 0; + for (let i = 0; i < track.rtp.length; i++) { + if (track.rtp[i].codec === "opus") { + opusIndex = i; + } + // TODO: maybe delete non-Opus candidates? + } + track.fmtp[opusIndex].config += `; maxaveragebitrate=${192 * 2 * 1024}; stereo=1; sprop-stereo=1 ; cbr=1`; + }); + + offer.sdp = SdpTransform.write(parsed); + console.log("New SDP", offer.sdp); + await this.pc.setLocalDescription(offer); await this.waitForIceCandidates(); this.ws!.send( diff --git a/src/navbar/index.tsx b/src/navbar/index.tsx index 025bd65..3190701 100644 --- a/src/navbar/index.tsx +++ b/src/navbar/index.tsx @@ -69,7 +69,9 @@ export function NavBar() { onClick={() => dispatch( broadcastState.connectionState === - "NOT_CONNECTED" + "NOT_CONNECTED" || + broadcastState.connectionState === + "CONNECTION_LOST" ? BroadcastState.startStreaming() : BroadcastState.stopStreaming() ) diff --git a/yarn.lock b/yarn.lock index bbb48d6..497dc29 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1550,6 +1550,11 @@ dependencies: "@types/node" "*" +"@types/sdp-transform@^2.4.3": + version "2.4.3" + resolved "https://registry.yarnpkg.com/@types/sdp-transform/-/sdp-transform-2.4.3.tgz#67cb3e8319f2de37e95e376002b89e870e19c69e" + integrity sha512-DaDNfnjtnO2KMw0XxO3cUEs9G6wioOCWnUTG/g24zh1jccCsV5hzHILZoDRds0LLFhKcMEJfoC7YFuMAYL51uw== + "@types/shallowequal@^1.1.1": version "1.1.1" resolved "https://registry.yarnpkg.com/@types/shallowequal/-/shallowequal-1.1.1.tgz#aad262bb3f2b1257d94c71d545268d592575c9b1" @@ -9538,6 +9543,11 @@ scss-tokenizer@^0.2.3: js-base64 "^2.1.8" source-map "^0.4.2" +sdp-transform@^2.14.0: + version "2.14.0" + resolved "https://registry.yarnpkg.com/sdp-transform/-/sdp-transform-2.14.0.tgz#222452e79e335f000fb9a9a2850021265d1da12d" + integrity sha512-8ZYOau/o9PzRhY0aMuRzvmiM6/YVQR8yjnBScvZHSdBnywK5oZzAJK+412ZKkDq29naBmR3bRw8MFu0C01Gehg== + select-hose@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/select-hose/-/select-hose-2.0.0.tgz#625d8658f865af43ec962bfc376a37359a4994ca"