You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

69 lines
2.1 KiB

var pc = null;
function negotiate() {
pc.addTransceiver('video', { direction: 'recvonly' });
return pc.createOffer().then((offer) => {
return pc.setLocalDescription(offer);
}).then(() => {
// wait for ICE gathering to complete
return new Promise((resolve) => {
if (pc.iceGatheringState === 'complete') {
resolve();
} else {
const checkState = () => {
if (pc.iceGatheringState === 'complete') {
pc.removeEventListener('icegatheringstatechange', checkState);
resolve();
}
};
pc.addEventListener('icegatheringstatechange', checkState);
}
});
}).then(() => {
var offer = pc.localDescription;
return fetch('/api/offer', {
body: JSON.stringify({
sdp: offer.sdp,
type: offer.type,
}),
headers: {
'Content-Type': 'application/json'
},
method: 'POST'
});
}).then((response) => {
return response.json();
}).then((answer) => {
return pc.setRemoteDescription(answer);
}).catch((e) => {
alert(e);
});
}
function start() {
console.log('开始执行!');
var config = {
sdpSemantics: 'unified-plan'
};
//config.iceServers = [{ urls: ['stun:stun.voiparound.com'] }];
pc = new RTCPeerConnection();
pc.addEventListener('track', (evt) => {
if (evt.track.kind == 'video') {
//document.getElementById('video').srcObject = evt.streams[0];
document.getElementById('u33_video').srcObject = evt.streams[0];
}
});
negotiate();
}
function showView(){
console.log('status:',document.getElementById('u33_video').paused)
if (document.getElementById('u33_video').paused) {
document.getElementById('u33_video').play().catch(error => {
console.error('Error playing video:', error);
});
}
}
function getChannellist(){
}