diff --git a/trunk/doc/CHANGELOG.md b/trunk/doc/CHANGELOG.md index 18a7b36a4..c831ec94b 100644 --- a/trunk/doc/CHANGELOG.md +++ b/trunk/doc/CHANGELOG.md @@ -7,6 +7,7 @@ The changelog for SRS. ## SRS 7.0 Changelog +* v7.0, 2024-10-15, Merge [#4160](https://github.com/ossrs/srs/pull/4160): RTC2RTMP: Fix screen sharing stutter caused by packet loss. v7.0.18 (#4160) * v7.0, 2024-10-15, Merge [#3979](https://github.com/ossrs/srs/pull/3979): ST: Use clock_gettime to prevent time jumping backwards. v7.0.17 (#3979) * v7.0, 2024-09-09, Merge [#4158](https://github.com/ossrs/srs/pull/4158): Proxy: Support proxy server for SRS. v7.0.16 (#4158) * v7.0, 2024-09-09, Merge [#4171](https://github.com/ossrs/srs/pull/4171): Heartbeat: Report ports for proxy server. v7.0.15 (#4171) @@ -29,6 +30,7 @@ The changelog for SRS. ## SRS 6.0 Changelog +* v6.0, 2024-10-15, Merge [#4160](https://github.com/ossrs/srs/pull/4160): RTC2RTMP: Fix screen sharing stutter caused by packet loss. v6.0.157 (#4160) * v6.0, 2024-09-09, Merge [#4171](https://github.com/ossrs/srs/pull/4171): Heartbeat: Report ports for proxy server. v6.0.156 (#4171) * v6.0, 2024-09-01, Merge [#4165](https://github.com/ossrs/srs/pull/4165): FLV: Refine source and http handler. v6.0.155 (#4165) * v6.0, 2024-09-01, Merge [#4166](https://github.com/ossrs/srs/pull/4166): Edge: Fix flv edge crash when http unmount. v6.0.154 (#4166) @@ -189,6 +191,7 @@ The changelog for SRS. ## SRS 5.0 Changelog +* v5.0, 2024-10-15, Merge [#4160](https://github.com/ossrs/srs/pull/4160): RTC2RTMP: Fix screen sharing stutter caused by packet loss. v5.0.216 (#4160) * v5.0, 2024-09-09, Merge [#4171](https://github.com/ossrs/srs/pull/4171): Heartbeat: Report ports for proxy server. v5.0.215 (#4171) * v5.0, 2024-07-24, Merge [#4126](https://github.com/ossrs/srs/pull/4126): Edge: Improve stability for state and fd closing. v5.0.214 (#4126) * v5.0, 2024-06-03, Merge [#4057](https://github.com/ossrs/srs/pull/4057): RTC: Support dropping h.264 SEI from NALUs. v5.0.213 (#4057) diff --git a/trunk/research/players/js/srs.sdk.js b/trunk/research/players/js/srs.sdk.js index 2a597883a..0e0c4fd47 100644 --- a/trunk/research/players/js/srs.sdk.js +++ b/trunk/research/players/js/srs.sdk.js @@ -527,36 +527,56 @@ function SrsRtcWhipWhepAsync() { // @url The WebRTC url to publish with, for example: // http://localhost:1985/rtc/v1/whip/?app=live&stream=livestream // @options The options to control playing, supports: - // videoOnly: boolean, whether only play video, default to false. - // audioOnly: boolean, whether only play audio, default to false. + // camera: boolean, whether capture video from camera, default to true. + // screen: boolean, whether capture video from screen, default to false. + // audio: boolean, whether play audio, default to true. self.publish = async function (url, options) { if (url.indexOf('/whip/') === -1) throw new Error(`invalid WHIP url ${url}`); - if (options?.videoOnly && options?.audioOnly) throw new Error(`The videoOnly and audioOnly in options can't be true at the same time`); + const hasAudio = options?.audio ?? true; + const useCamera = options?.camera ?? true; + const useScreen = options?.screen ?? false; + + if (!hasAudio && !useCamera && !useScreen) throw new Error(`The camera, screen and audio can't be false at the same time`); - if (!options?.videoOnly) { + if (hasAudio) { self.pc.addTransceiver("audio", {direction: "sendonly"}); } else { self.constraints.audio = false; } - if (!options?.audioOnly) { + if (useCamera || useScreen) { self.pc.addTransceiver("video", {direction: "sendonly"}); - } else { + } + + if (!useCamera) { self.constraints.video = false; } if (!navigator.mediaDevices && window.location.protocol === 'http:' && window.location.hostname !== 'localhost') { throw new SrsError('HttpsRequiredError', `Please use HTTPS or localhost to publish, read https://github.com/ossrs/srs/issues/2762#issuecomment-983147576`); } - var stream = await navigator.mediaDevices.getUserMedia(self.constraints); - // @see https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/addStream#Migrating_to_addTrack - stream.getTracks().forEach(function (track) { - self.pc.addTrack(track); + if (useScreen) { + const displayStream = await navigator.mediaDevices.getDisplayMedia({ + video: true + }); + // @see https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/addStream#Migrating_to_addTrack + displayStream.getTracks().forEach(function (track) { + self.pc.addTrack(track); + // Notify about local track when stream is ok. + self.ontrack && self.ontrack({track: track}); + }); + } - // Notify about local track when stream is ok. - self.ontrack && self.ontrack({track: track}); - }); + if (useCamera || hasAudio) { + const userStream = await navigator.mediaDevices.getUserMedia(self.constraints); + + userStream.getTracks().forEach(function (track) { + self.pc.addTrack(track); + // Notify about local track when stream is ok. + self.ontrack && self.ontrack({track: track}); + }); + } var offer = await self.pc.createOffer(); await self.pc.setLocalDescription(offer); diff --git a/trunk/research/players/whip.html b/trunk/research/players/whip.html index 60067fe7b..11e4ac993 100644 --- a/trunk/research/players/whip.html +++ b/trunk/research/players/whip.html @@ -62,10 +62,16 @@