@ -526,11 +526,24 @@ function SrsRtcWhipWhepAsync() {
// See https://datatracker.ietf.org/doc/draft-ietf-wish-whip/
// @url The WebRTC url to publish with, for example:
// http://localhost:1985/rtc/v1/whip/?app=live&stream=livestream
self . publish = async function ( url ) {
// @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.
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 ` ) ;
self . pc . addTransceiver ( "audio" , { direction : "sendonly" } ) ;
self . pc . addTransceiver ( "video" , { direction : "sendonly" } ) ;
if ( ! options ? . videoOnly ) {
self . pc . addTransceiver ( "audio" , { direction : "sendonly" } ) ;
} else {
self . constraints . audio = false ;
}
if ( ! options ? . audioOnly ) {
self . pc . addTransceiver ( "video" , { direction : "sendonly" } ) ;
} else {
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 ` ) ;
@ -548,7 +561,7 @@ function SrsRtcWhipWhepAsync() {
var offer = await self . pc . createOffer ( ) ;
await self . pc . setLocalDescription ( offer ) ;
const answer = await new Promise ( function ( resolve , reject ) {
console . log ( "Generated offer: " , offer ) ;
console . log ( ` Generated offer: ${ offer . sdp } ` ) ;
const xhr = new XMLHttpRequest ( ) ;
xhr . onload = function ( ) {
@ -572,16 +585,20 @@ function SrsRtcWhipWhepAsync() {
// See https://datatracker.ietf.org/doc/draft-ietf-wish-whip/
// @url The WebRTC url to play with, for example:
// http://localhost:1985/rtc/v1/whep/?app=live&stream=livestream
self . play = async function ( url ) {
// @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.
self . play = async function ( url , options ) {
if ( url . indexOf ( '/whip-play/' ) === - 1 && url . indexOf ( '/whep/' ) === - 1 ) throw new Error ( ` invalid WHEP url ${ url } ` ) ;
if ( options ? . videoOnly && options ? . audioOnly ) throw new Error ( ` The videoOnly and audioOnly in options can't be true at the same time ` ) ;
self . pc . addTransceiver ( "audio" , { direction : "recvonly" } ) ;
self . pc . addTransceiver ( "video" , { direction : "recvonly" } ) ;
if ( ! options ? . videoOnly ) self . pc . addTransceiver ( "audio" , { direction : "recvonly" } ) ;
if ( ! options ? . audioOnly ) self . pc . addTransceiver ( "video" , { direction : "recvonly" } ) ;
var offer = await self . pc . createOffer ( ) ;
await self . pc . setLocalDescription ( offer ) ;
const answer = await new Promise ( function ( resolve , reject ) {
console . log ( "Generated offer: " , offer ) ;
console . log ( ` Generated offer: ${ offer . sdp } ` ) ;
const xhr = new XMLHttpRequest ( ) ;
xhr . onload = function ( ) {