Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit 04aa581

Browse files
zhenqi522lzhai
authored andcommitted
Add resolution options for forward stream (#126)
1 parent 1c9e532 commit 04aa581

File tree

2 files changed

+40
-12
lines changed

2 files changed

+40
-12
lines changed

src/samples/conference/public/index.html

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@
3636
<div style="width:320px;height:240" class="local">
3737
<video playsinline muted autoplay style="width:320px;height:240"></video>
3838
</div>
39-
<div id="resolutions"><span>Try a different resolution:&nbsp;</span></div>
40-
<div class="remote">
41-
<video playsinline autoplay controls></video>
42-
</div>
4339
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
4440
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js" type="text/javascript"></script>
4541
<script src="https://webrtchacks.github.io/adapter/adapter-7.0.0.js" type="text/javascript"></script>

src/samples/conference/public/scripts/index.js

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)