@@ -46,18 +46,47 @@ const runSocketIOSample = function() {
4646 }
4747
4848 var subscribeForward = getParameterByName ( 'forward' ) === 'true' ?true :false ;
49-
49+ var isSelf = getParameterByName ( 'self' ) === 'false' ? false : true ;
5050 conference = new Owt . Conference . ConferenceClient ( ) ;
5151 function renderVideo ( stream ) {
52+ let subscirptionForward = null ;
53+ function subscribeDifferentResolutionForward ( forward , resolution ) {
54+ subscirptionForward && subscirptionForward . stop ( ) ;
55+ subscirptionForward = null ;
56+ const videoOptions = { } ;
57+ videoOptions . resolution = resolution ;
58+ conference . subscribe ( stream , {
59+ audio : true ,
60+ video : videoOptions
61+ } ) . then ( (
62+ subscription ) => {
63+ subscirptionForward = subscription ;
64+ $ ( `#${ stream . id } ` ) . get ( 0 ) . srcObject = stream . mediaStream ;
65+ } ) ;
66+ }
67+ let $p = $ ( `<div id=${ stream . id } resolutions> </div>` )
68+ for ( const resolution of stream . capabilities . video . resolutions ) {
69+ const button = $ ( '<button/>' , {
70+ text : resolution . width + 'x' +
71+ resolution . height ,
72+ click : ( ) => {
73+ subscribeDifferentResolutionForward ( stream , resolution ) ;
74+ }
75+ } ) ;
76+ button . appendTo ( $p ) ;
77+ } ;
78+ $p . appendTo ( $ ( 'body' ) ) ;
5279 conference . subscribe ( stream )
53- . then ( ( subscriptions ) => {
54- let $video = $ ( `<video controls autoplay id=${ stream . id } width="320" height="240">this browser does not supported video tag</video>` ) ;
80+ . then ( ( subscription ) => {
81+ subscirptionForward = subscription ;
82+ let $video = $ ( `<video controls autoplay id=${ stream . id } style="display:block" >this browser does not supported video tag</video>` ) ;
5583 $video . get ( 0 ) . srcObject = stream . mediaStream ;
56- $ ( 'body' ) . append ( $video ) ;
84+ $p . append ( $video ) ;
5785 } , ( err ) => { console . log ( 'subscribe failed' , err ) ;
5886 } ) ;
5987 stream . addEventListener ( 'ended' , ( ) => {
6088 removeUi ( stream . id ) ;
89+ $ ( `#${ stream . id } resolutions` ) . remove ( ) ;
6190 } ) ;
6291 }
6392 function removeUi ( id ) {
@@ -74,13 +103,14 @@ const runSocketIOSample = function() {
74103 } ) . then ( (
75104 subscription ) => {
76105 subscriptionForMixedStream = subscription ;
77- $ ( '.remote video' ) . get ( 0 ) . srcObject = stream . mediaStream ;
106+ $ ( `# ${ stream . id } ` ) . get ( 0 ) . srcObject = stream . mediaStream ;
78107 } ) ;
79108 }
80109
81110 conference . addEventListener ( 'streamadded' , ( event ) => {
82111 console . log ( 'A new stream is added ' , event . stream . id ) ;
83- subscribeForward && renderVideo ( event . stream ) ;
112+ isSelf = isSelf ?isSelf :event . stream . id != publicationGlobal . id ;
113+ subscribeForward && isSelf && renderVideo ( event . stream ) ;
84114 mixStream ( myRoom , event . stream . id , 'common' ) ;
85115 event . stream . addEventListener ( 'ended' , ( ) => {
86116 console . log ( event . stream . id + ' is ended.' ) ;
@@ -139,7 +169,9 @@ const runSocketIOSample = function() {
139169 video : true
140170 } ) . then ( ( subscription ) => {
141171 subscriptionForMixedStream = subscription ;
142- $ ( '.remote video' ) . get ( 0 ) . srcObject = stream . mediaStream ;
172+ let $video = $ ( `<video controls autoplay id=${ stream . id } style='display:block'>this browser does not supported video tag</video>` ) ;
173+ $video . get ( 0 ) . srcObject = stream . mediaStream ;
174+ $ ( 'body' ) . append ( $video ) ;
143175 subscription . addEventListener ( 'error' , ( err ) => {
144176 console . log ( 'Subscription error: ' + err . error . message ) ;
145177 } )
@@ -152,7 +184,7 @@ const runSocketIOSample = function() {
152184 subscribeDifferentResolution ( stream , resolution ) ;
153185 }
154186 } ) ;
155- button . appendTo ( $ ( '#resolutions ' ) ) ;
187+ button . appendTo ( $ ( 'body ' ) ) ;
156188 } ;
157189 }
158190 } else if ( stream . source . audio !== 'mixed' ) {
0 commit comments