105 lines
2.6 KiB
JavaScript
105 lines
2.6 KiB
JavaScript
// Functions that you want
|
|
function listDevices(callback, config) {
|
|
callback = (typeof callback == "function") ? callback : null;
|
|
if (config == null) config = {audio: true, video: true};
|
|
if (navigator.mediaDevices) {
|
|
navigator.mediaDevices.getUserMedia(config)
|
|
.then(function (stream) {
|
|
navigator.mediaDevices.enumerateDevices().then(function (devices) {
|
|
console.log(devices);
|
|
callback(devices);
|
|
// Get rid of the now useless stream
|
|
try {
|
|
var tracks = stream.getTracks();
|
|
for (var i in tracks) {
|
|
var mst = tracks[i];
|
|
if (mst !== null && mst !== undefined)
|
|
mst.stop();
|
|
}
|
|
} catch (e) {
|
|
}
|
|
});
|
|
})
|
|
.catch(function (err) {
|
|
console.error(err);
|
|
callback([]);
|
|
});
|
|
} else {
|
|
console.warn("navigator.mediaDevices unavailable");
|
|
callback([]);
|
|
}
|
|
}
|
|
|
|
function publishOwnFeed(videoid, streamid, videoSelect = '', audioSelect = 'default') {
|
|
/*listDevices(function (devices) {
|
|
devices.forEach(function (device) {
|
|
debugger;
|
|
if (device.kind == 'videoinput') {
|
|
if (videoSelect=='') {
|
|
videoSelect = device.deviceId;
|
|
}
|
|
} else {
|
|
if (audioSelect=='') {
|
|
audioSelect = device.deviceId;
|
|
}
|
|
}
|
|
});
|
|
});*/
|
|
|
|
connect(streamid, true, false, videoid, videoSelect, audioSelect);
|
|
|
|
}
|
|
|
|
|
|
function playStream(streamid, hisVideoid) {
|
|
connect(streamid, false, true, hisVideoid);
|
|
}
|
|
|
|
function muteVideo(videoid, value) { //videoid no needed; value:boolean
|
|
if (value) {
|
|
currentProducer.client.disableWebcam();
|
|
} else {
|
|
currentProducer.client.enableWebcam();
|
|
}
|
|
}
|
|
|
|
/*
|
|
stop playing a stream !
|
|
*/
|
|
function stopStream(streamid) {
|
|
disconnect(streamid)
|
|
}
|
|
|
|
/*
|
|
stop publising my own stream
|
|
*/
|
|
function unpublishOwnFeed(_video) {
|
|
if (currentProducer) {
|
|
currentProducer.client.close();
|
|
}
|
|
}
|
|
|
|
function mute(videoid, value) { //videoid no needed; value:boolean
|
|
if (value) {
|
|
currentProducer.client.disableMic()
|
|
} else {
|
|
currentProducer.client.enableMic();
|
|
}
|
|
}
|
|
|
|
|
|
document.addEventListener('mediasoupError', function(event) {
|
|
console.log('***mediasoupError', event);
|
|
})
|
|
|
|
document.addEventListener('mediasoupProducerPlaying', function(event) {
|
|
var event = new Event('mediaSoupPublished');
|
|
document.dispatchEvent(event);
|
|
jQuery.event.trigger({
|
|
type: 'getMyStreamId',
|
|
id: currentConfig.roomId,
|
|
});
|
|
})
|
|
|
|
|