bigbluebutton-Github/bigbluebutton-html5/client/compatibility/kurento-extension.js

809 lines
23 KiB
JavaScript
Raw Normal View History

2018-03-08 05:20:37 +08:00
const isFirefox = typeof window.InstallTrigger !== 'undefined';
const isOpera = !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;
const isChrome = !!window.chrome && !isOpera;
const isSafari = navigator.userAgent.indexOf('Safari') >= 0 && !isChrome;
const isElectron = navigator.userAgent.toLowerCase().indexOf(' electron/') > -1;
2019-01-22 02:02:57 +08:00
const hasDisplayMedia = (typeof navigator.getDisplayMedia === 'function'
|| typeof navigator.mediaDevices.getDisplayMedia === 'function');
2018-03-08 05:20:37 +08:00
const kurentoHandler = null;
Kurento = function (
2018-03-08 05:20:37 +08:00
tag,
voiceBridge,
userId,
2018-03-08 05:20:37 +08:00
internalMeetingId,
onFail,
onSuccess,
options = {},
2018-03-08 05:20:37 +08:00
) {
this.ws = null;
this.video = null;
this.screen = null;
this.webRtcPeer = null;
this.mediaCallback = null;
this.renderTag = tag;
this.voiceBridge = voiceBridge;
this.userId = userId;
this.internalMeetingId = internalMeetingId;
// Optional parameters are: userName, caleeName, chromeExtension, wsUrl, iceServers,
// chromeScreenshareSources, firefoxScreenshareSource
Object.assign(this, options);
2018-08-23 23:49:16 +08:00
this.SEND_ROLE = 'send';
this.RECV_ROLE = 'recv';
this.SFU_APP = 'screenshare';
this.ON_ICE_CANDIDATE_MSG = 'iceCandidate';
this.PING_INTERVAL = 15000;
2018-07-26 04:04:20 +08:00
window.Logger = this.logger || console;
if (this.wsUrl == null) {
this.defaultPath = 'bbb-webrtc-sfu';
this.hostName = window.location.hostname;
this.wsUrl = `wss://${this.hostName}/${this.defaultPath}`;
}
if (this.chromeScreenshareSources == null) {
2018-08-23 23:49:16 +08:00
this.chromeScreenshareSources = ['screen', 'window'];
}
if (this.firefoxScreenshareSource == null) {
2018-08-23 23:49:16 +08:00
this.firefoxScreenshareSource = 'window';
}
2018-05-10 07:38:20 +08:00
// Limiting max resolution to WQXGA
// In FireFox we force full screen share and in the case
// of multiple screens the total area shared becomes too large
2018-05-10 07:38:20 +08:00
this.vid_max_width = 2560;
this.vid_max_height = 1600;
this.width = window.screen.width;
this.height = window.screen.height;
this.userId = userId;
this.pingInterval = null;
if (onFail != null) {
this.onFail = Kurento.normalizeCallback(onFail);
} else {
2018-03-08 05:20:37 +08:00
const _this = this;
this.onFail = function () {
_this.logError('Default error handler');
};
}
if (onSuccess != null) {
this.onSuccess = Kurento.normalizeCallback(onSuccess);
} else {
2018-08-23 23:49:16 +08:00
const _this = this;
this.onSuccess = function () {
_this.logSuccess('Default success handler');
};
}
};
2018-03-08 05:20:37 +08:00
this.KurentoManager = function () {
this.kurentoVideo = null;
this.kurentoScreenshare = null;
this.kurentoAudio = null;
};
KurentoManager.prototype.exitScreenShare = function () {
2018-03-08 05:20:37 +08:00
if (typeof this.kurentoScreenshare !== 'undefined' && this.kurentoScreenshare) {
if (this.kurentoScreenshare.logger !== null) {
this.kurentoScreenshare.logger.info(' [exitScreenShare] Exiting screensharing');
}
if(this.kurentoScreenshare.webRtcPeer) {
this.kurentoScreenshare.webRtcPeer.peerConnection.oniceconnectionstatechange = null;
}
2018-03-08 05:20:37 +08:00
if (this.kurentoScreenshare.ws !== null) {
this.kurentoScreenshare.ws.onclose = function () {};
this.kurentoScreenshare.ws.close();
}
if (this.kurentoScreenshare.pingInterval) {
clearInterval(this.kurentoScreenshare.pingInterval);
}
this.kurentoScreenshare.dispose();
this.kurentoScreenshare = null;
}
};
KurentoManager.prototype.exitVideo = function () {
try {
if (typeof this.kurentoVideo !== 'undefined' && this.kurentoVideo) {
if(this.kurentoVideo.webRtcPeer) {
this.kurentoVideo.webRtcPeer.peerConnection.oniceconnectionstatechange = null;
}
if (this.kurentoVideo.logger !== null) {
this.kurentoVideo.logger.info(' [exitScreenShare] Exiting screensharing viewing');
}
if (this.kurentoVideo.ws !== null) {
this.kurentoVideo.ws.onclose = function () {};
this.kurentoVideo.ws.close();
}
if (this.kurentoVideo.pingInterval) {
clearInterval(this.kurentoVideo.pingInterval);
}
this.kurentoVideo.dispose();
this.kurentoVideo = null;
}
}
catch (err) {
if (this.kurentoVideo) {
this.kurentoVideo.dispose();
this.kurentoVideo = null;
}
}
};
KurentoManager.prototype.exitAudio = function () {
if (typeof this.kurentoAudio !== 'undefined' && this.kurentoAudio) {
if (this.kurentoAudio.logger !== null) {
this.kurentoAudio.logger.info(' [exitAudio] Exiting listen only audio');
}
if (this.kurentoAudio.ws !== null) {
this.kurentoAudio.ws.onclose = function () {};
this.kurentoAudio.ws.close();
}
if (this.kurentoAudio.pingInterval) {
clearInterval(this.kurentoAudio.pingInterval);
}
this.kurentoAudio.dispose();
this.kurentoAudio = null;
}
};
KurentoManager.prototype.shareScreen = function (tag) {
this.exitScreenShare();
2018-03-08 05:20:37 +08:00
const obj = Object.create(Kurento.prototype);
Kurento.apply(obj, arguments);
this.kurentoScreenshare = obj;
this.kurentoScreenshare.setScreensharing(tag);
};
KurentoManager.prototype.joinWatchVideo = function (tag) {
this.exitVideo();
2018-03-08 05:20:37 +08:00
const obj = Object.create(Kurento.prototype);
Kurento.apply(obj, arguments);
this.kurentoVideo = obj;
this.kurentoVideo.setWatchVideo(tag);
};
KurentoManager.prototype.getFirefoxScreenshareSource = function () {
return this.kurentoScreenshare.firefoxScreenshareSource;
2018-08-23 23:49:16 +08:00
};
KurentoManager.prototype.getChromeScreenshareSources = function () {
return this.kurentoScreenshare.chromeScreenshareSources;
2018-08-23 23:49:16 +08:00
};
KurentoManager.prototype.getChromeExtensionKey = function () {
return this.kurentoScreenshare.chromeExtension;
2018-08-23 23:49:16 +08:00
};
Kurento.prototype.setScreensharing = function (tag) {
this.mediaCallback = this.startScreensharing.bind(this);
this.create(tag);
};
Kurento.prototype.create = function (tag) {
this.setRenderTag(tag);
this.init();
};
Kurento.prototype.downscaleResolution = function (oldWidth, oldHeight) {
const factorWidth = this.vid_max_width / oldWidth;
const factorHeight = this.vid_max_height / oldHeight;
2018-08-23 23:49:16 +08:00
let width,
height;
if (factorWidth < factorHeight) {
width = Math.trunc(oldWidth * factorWidth);
height = Math.trunc(oldHeight * factorWidth);
2018-08-23 23:49:16 +08:00
} else {
width = Math.trunc(oldWidth * factorHeight);
height = Math.trunc(oldHeight * factorHeight);
}
return { width, height };
};
Kurento.prototype.init = function () {
2018-03-08 05:20:37 +08:00
const self = this;
if ('WebSocket' in window) {
this.logger.info('this browser supports websockets');
this.ws = new WebSocket(this.wsUrl);
this.ws.onmessage = this.onWSMessage.bind(this);
this.ws.onclose = (close) => {
kurentoManager.exitScreenShare();
2018-03-08 05:20:37 +08:00
self.onFail('Websocket connection closed');
};
this.ws.onerror = (error) => {
kurentoManager.exitScreenShare();
2018-03-08 05:20:37 +08:00
self.onFail('Websocket connection error');
};
this.ws.onopen = function () {
self.pingInterval = setInterval(self.ping.bind(self), self.PING_INTERVAL);
self.mediaCallback();
2018-03-08 05:20:37 +08:00
};
} else { this.logger.info('this browser does not support websockets'); }
};
Kurento.prototype.onWSMessage = function (message) {
2018-03-08 05:20:37 +08:00
const parsedMessage = JSON.parse(message.data);
switch (parsedMessage.id) {
case 'startResponse':
this.startResponse(parsedMessage);
break;
case 'stopSharing':
kurentoManager.exitScreenShare();
break;
case 'iceCandidate':
this.webRtcPeer.addIceCandidate(parsedMessage.candidate);
break;
case 'webRTCAudioSuccess':
this.onSuccess(parsedMessage.success);
break;
case 'webRTCAudioError':
this.onFail(parsedMessage);
break;
case 'pong':
break;
default:
this.logger.error('Unrecognized message', parsedMessage);
}
};
Kurento.prototype.setRenderTag = function (tag) {
this.renderTag = tag;
};
Kurento.prototype.startResponse = function (message) {
2018-03-08 05:20:37 +08:00
if (message.response !== 'accepted') {
const errorMsg = message.message ? message.message : 'Unknow error';
2018-08-23 23:49:16 +08:00
this.logger.warn('Call not accepted for the following reason:', { error: errorMsg });
switch (message.type) {
case 'screenshare':
if (message.role === this.SEND_ROLE) {
kurentoManager.exitScreenShare();
2018-08-23 23:49:16 +08:00
} else if (message.role === this.RECV_ROLE) {
kurentoManager.exitVideo();
}
break;
case 'audio':
kurentoManager.exitAudio();
break;
}
} else {
2018-08-23 23:49:16 +08:00
this.logger.debug(`Procedure for ${message.type} was accepted with SDP =>`, { sdpAnswer: message.sdpAnswer });
this.webRtcPeer.processAnswer(message.sdpAnswer);
}
2018-03-08 05:20:37 +08:00
};
Kurento.prototype.onOfferPresenter = function (error, offerSdp) {
2018-03-08 05:20:37 +08:00
const self = this;
2018-03-08 05:20:37 +08:00
if (error) {
this.logger.info(`Kurento.prototype.onOfferPresenter Error ${error}`);
this.onFail(error);
return;
}
2018-03-08 05:20:37 +08:00
const message = {
id: 'start',
type: this.SFU_APP,
role: this.SEND_ROLE,
internalMeetingId: self.internalMeetingId,
voiceBridge: self.voiceBridge,
callerName: self.userId,
2018-03-08 05:20:37 +08:00
sdpOffer: offerSdp,
vh: this.height,
vw: this.width,
};
2018-08-23 23:49:16 +08:00
this.logger.info('onOfferPresenter sending to screenshare server => ', { sdpOffer: message });
this.sendMessage(message);
2018-03-08 05:20:37 +08:00
};
Kurento.prototype.startScreensharing = function () {
2018-03-08 05:20:37 +08:00
if (window.chrome) {
if (this.chromeExtension == null) {
this.logError({
2018-03-08 05:20:37 +08:00
status: 'failed',
message: 'Missing Chrome Extension key',
});
this.onFail();
return;
}
}
2018-03-08 05:20:37 +08:00
const options = {
localVideo: document.getElementById(this.renderTag),
onicecandidate: (candidate) => {
this.onIceCandidate(candidate, this.SEND_ROLE);
},
2018-03-08 05:20:37 +08:00
sendSource: 'desktop',
};
2018-08-23 23:49:16 +08:00
this.logger.info(' Peer options =>', options);
2018-05-10 07:38:20 +08:00
let resolution;
this.logger.debug(`Screenshare screen dimensions are ${this.width} x ${this.height}`);
2018-05-10 07:38:20 +08:00
if (this.width > this.vid_max_width || this.height > this.vid_max_height) {
resolution = this.downscaleResolution(this.width, this.height);
this.width = resolution.width;
this.height = resolution.height;
2018-08-23 23:49:16 +08:00
this.logger.debug('Screenshare track dimensions have been resized to', this.width, 'x', this.height);
2018-05-10 07:38:20 +08:00
}
this.addIceServers(this.iceServers, options);
this.webRtcPeer = kurentoUtils.WebRtcPeer.WebRtcPeerSendonly(options, (error) => {
2018-03-08 05:20:37 +08:00
if (error) {
2018-08-23 23:49:16 +08:00
this.logger.error('WebRtcPeerSendonly constructor error:', { error });
this.onFail(error);
return kurentoManager.exitScreenShare();
}
this.webRtcPeer.generateOffer(this.onOfferPresenter.bind(this));
2018-08-23 23:49:16 +08:00
this.logger.info('Generated peer offer w/ options:', { options });
const localStream = this.webRtcPeer.peerConnection.getLocalStreams()[0];
2018-08-28 23:40:26 +08:00
const _this = this;
localStream.getVideoTracks()[0].onended = function () {
2018-08-28 23:40:26 +08:00
_this.webRtcPeer.peerConnection.oniceconnectionstatechange = null;
return kurentoManager.exitScreenShare();
};
localStream.getVideoTracks()[0].oninactive = function () {
return kurentoManager.exitScreenShare();
};
});
this.webRtcPeer.peerConnection.oniceconnectionstatechange = () => {
2018-08-23 23:49:16 +08:00
if (this.webRtcPeer) {
const connectionState = this.webRtcPeer.peerConnection.iceConnectionState;
2018-08-28 23:40:26 +08:00
if (connectionState === 'failed' || connectionState === 'closed') {
this.webRtcPeer.peerConnection.oniceconnectionstatechange = null;
2018-08-23 02:51:25 +08:00
this.onFail('ICE connection failed');
}
}
};
2018-03-08 05:20:37 +08:00
};
Kurento.prototype.onIceCandidate = function (candidate, role) {
2018-03-08 05:20:37 +08:00
const self = this;
2018-08-23 23:49:16 +08:00
this.logger.info('Local candidate:', { candidate });
2018-03-08 05:20:37 +08:00
const message = {
id: this.ON_ICE_CANDIDATE_MSG,
2018-08-23 23:49:16 +08:00
role,
type: this.SFU_APP,
voiceBridge: self.voiceBridge,
2018-03-08 05:20:37 +08:00
candidate,
callerName: self.userId,
2018-03-08 05:20:37 +08:00
};
this.sendMessage(message);
2018-03-08 05:20:37 +08:00
};
Kurento.prototype.setWatchVideo = function (tag) {
this.useVideo = true;
this.useCamera = 'none';
this.useMic = 'none';
this.mediaCallback = this.viewer;
this.create(tag);
};
Kurento.prototype.viewer = function () {
2018-03-08 05:20:37 +08:00
const self = this;
if (!this.webRtcPeer) {
2018-03-08 05:20:37 +08:00
const options = {
mediaConstraints: {
2018-08-23 23:49:16 +08:00
audio: false,
},
remoteVideo: document.getElementById(this.renderTag),
onicecandidate: (candidate) => {
this.onIceCandidate(candidate, this.RECV_ROLE);
2018-08-23 23:49:16 +08:00
},
};
this.addIceServers(this.iceServers, options);
2018-03-08 05:20:37 +08:00
self.webRtcPeer = kurentoUtils.WebRtcPeer.WebRtcPeerRecvonly(options, function (error) {
if (error) {
return self.onFail(error);
}
this.generateOffer(self.onOfferViewer.bind(self));
});
self.webRtcPeer.peerConnection.oniceconnectionstatechange = () => {
2018-08-23 23:49:16 +08:00
if (this.webRtcPeer) {
const connectionState = this.webRtcPeer.peerConnection.iceConnectionState;
if (connectionState === 'failed' || connectionState === 'closed') {
this.webRtcPeer.peerConnection.oniceconnectionstatechange = null;
2018-08-23 02:51:25 +08:00
this.onFail('ICE connection failed');
}
}
};
}
};
Kurento.prototype.onOfferViewer = function (error, offerSdp) {
2018-03-08 05:20:37 +08:00
const self = this;
if (error) {
this.logger.info(`Kurento.prototype.onOfferViewer Error ${error}`);
return this.onFail();
}
2018-03-08 05:20:37 +08:00
const message = {
id: 'start',
type: this.SFU_APP,
role: this.RECV_ROLE,
internalMeetingId: self.internalMeetingId,
voiceBridge: self.voiceBridge,
callerName: self.userId,
2018-03-08 05:20:37 +08:00
sdpOffer: offerSdp,
};
2018-08-23 23:49:16 +08:00
this.logger.info('onOfferViewer sending to screenshare server: ', { sdpOffer: message.sdpOffer });
this.sendMessage(message);
};
KurentoManager.prototype.joinAudio = function (tag) {
this.exitAudio();
2018-08-23 23:49:16 +08:00
const obj = Object.create(Kurento.prototype);
Kurento.apply(obj, arguments);
2018-08-23 23:49:16 +08:00
this.kurentoAudio = obj;
this.kurentoAudio.setAudio(tag);
};
Kurento.prototype.setAudio = function (tag) {
this.mediaCallback = this.listenOnly.bind(this);
this.create(tag);
};
Kurento.prototype.listenOnly = function () {
var self = this;
if (!this.webRtcPeer) {
var options = {
onicecandidate : this.onListenOnlyIceCandidate.bind(this),
mediaConstraints: {
2018-08-23 23:49:16 +08:00
audio: true,
video: false,
},
};
this.addIceServers(this.iceServers, options);
2018-08-23 23:49:16 +08:00
self.webRtcPeer = kurentoUtils.WebRtcPeer.WebRtcPeerRecvonly(options, function (error) {
if (error) {
return self.onFail(PEER_ERROR);
}
this.generateOffer(self.onOfferListenOnly.bind(self));
});
}
};
Kurento.prototype.onListenOnlyIceCandidate = function (candidate) {
2018-08-23 23:49:16 +08:00
const self = this;
this.logger.debug('[onListenOnlyIceCandidate]', { candidate });
2018-08-23 23:49:16 +08:00
const message = {
id: this.ON_ICE_CANDIDATE_MSG,
type: 'audio',
role: 'viewer',
voiceBridge: self.voiceBridge,
2018-08-23 23:49:16 +08:00
candidate,
};
this.sendMessage(message);
};
Kurento.prototype.onOfferListenOnly = function (error, offerSdp) {
2018-08-23 23:49:16 +08:00
const self = this;
if (error) {
this.logger.error('[onOfferListenOnly]', error);
return this.onFail(SDP_ERROR);
}
2018-08-23 23:49:16 +08:00
const message = {
id: 'start',
type: 'audio',
role: 'viewer',
voiceBridge: self.voiceBridge,
caleeName: self.caleeName,
2018-08-23 23:49:16 +08:00
sdpOffer: offerSdp,
userId: self.userId,
userName: self.userName,
2018-08-23 23:49:16 +08:00
internalMeetingId: self.internalMeetingId,
};
2018-08-23 23:49:16 +08:00
this.logger.debug('[onOfferListenOnly]', { message });
this.sendMessage(message);
};
Kurento.prototype.pauseTrack = function (message) {
const localStream = this.webRtcPeer.peerConnection.getLocalStreams()[0];
const track = localStream.getVideoTracks()[0];
if (track) {
track.enabled = false;
}
2018-08-23 23:49:16 +08:00
};
Kurento.prototype.resumeTrack = function (message) {
const localStream = this.webRtcPeer.peerConnection.getLocalStreams()[0];
const track = localStream.getVideoTracks()[0];
if (track) {
track.enabled = true;
}
2018-08-23 23:49:16 +08:00
};
Kurento.prototype.addIceServers = function (iceServers, options) {
2018-08-23 23:49:16 +08:00
this.logger.debug('Adding iceServers', iceServers);
if (iceServers && iceServers.length > 0) {
options.configuration = {};
options.configuration.iceServers = iceServers;
}
};
2018-03-08 05:20:37 +08:00
Kurento.prototype.stop = function () {
// if (this.webRtcPeer) {
// var message = {
// id : 'stop',
// type : 'screenshare',
// voiceBridge: kurentoHandler.voiceBridge
// }
// kurentoHandler.sendMessage(message);
// kurentoHandler.disposeScreenShare();
2018-03-08 05:20:37 +08:00
// }
};
2018-03-08 05:20:37 +08:00
Kurento.prototype.dispose = function () {
if (this.webRtcPeer) {
this.webRtcPeer.dispose();
this.webRtcPeer = null;
}
2018-03-08 05:20:37 +08:00
};
Kurento.prototype.ping = function () {
const message = {
2018-08-23 23:49:16 +08:00
id: 'ping',
};
this.sendMessage(message);
2018-08-23 23:49:16 +08:00
};
2018-03-08 05:20:37 +08:00
Kurento.prototype.sendMessage = function (message) {
const jsonMessage = JSON.stringify(message);
2018-08-23 23:49:16 +08:00
this.logger.info('Sending message:', { message });
this.ws.send(jsonMessage);
2018-03-08 05:20:37 +08:00
};
Kurento.prototype.logger = function (obj) {
this.logger.info(obj);
};
Kurento.prototype.logError = function (obj) {
this.logger.error(obj);
};
Kurento.normalizeCallback = function (callback) {
2018-03-08 05:20:37 +08:00
if (typeof callback === 'function') {
return callback;
}
this.logger.info(document.getElementById('BigBlueButton')[callback]);
2018-03-08 05:20:37 +08:00
return function (args) {
document.getElementById('BigBlueButton')[callback](args);
};
};
/* Global methods */
// this function explains how to use above methods/objects
2018-03-08 05:20:37 +08:00
window.getScreenConstraints = function (sendSource, callback) {
let screenConstraints = { video: {}, audio: false };
// Limiting FPS to a range of 5-10 (5 ideal)
2018-03-08 05:20:37 +08:00
screenConstraints.video.frameRate = { ideal: 5, max: 10 };
2018-05-10 07:38:20 +08:00
screenConstraints.video.height = { max: kurentoManager.kurentoScreenshare.vid_max_height };
screenConstraints.video.width = { max: kurentoManager.kurentoScreenshare.vid_max_width };
const getChromeScreenConstraints = function (extensionKey) {
return new Promise((resolve, reject) => {
chrome.runtime.sendMessage(
extensionKey,
{
getStream: true,
sources: kurentoManager.getChromeScreenshareSources(),
},
(response) => {
resolve(response);
}
);
});
};
const getDisplayMediaConstraints = function () {
// The fine-grained constraints (e.g.: frameRate) are supposed to go into
// the MediaStream because getDisplayMedia does not support them,
// so they're passed differently
kurentoManager.kurentoScreenshare.extensionInstalled = true;
optionalConstraints.width = { max: kurentoManager.kurentoScreenshare.vid_max_width };
optionalConstraints.height = { max: kurentoManager.kurentoScreenshare.vid_max_height };
optionalConstraints.frameRate = { ideal: 5, max: 10 };
let gDPConstraints = {
video: true,
optional: optionalConstraints
}
return gDPConstraints;
};
const optionalConstraints = [
{ googCpuOveruseDetection: true },
{ googCpuOveruseEncodeUsage: true },
{ googCpuUnderuseThreshold: 55 },
{ googCpuOveruseThreshold: 100 },
{ googPayloadPadding: true },
{ googScreencastMinBitrate: 600 },
{ googHighStartBitrate: true },
{ googHighBitrate: true },
{ googVeryHighBitrate: true },
];
if (isElectron) {
2018-10-19 01:03:11 +08:00
const sourceId = ipcRenderer.sendSync('screen-chooseSync');
kurentoManager.kurentoScreenshare.extensionInstalled = true;
2018-10-19 01:03:11 +08:00
// this statement sets gets 'sourceId" and sets "chromeMediaSourceId"
screenConstraints.video.chromeMediaSource = { exact: [sendSource] };
screenConstraints.video.chromeMediaSourceId = sourceId;
screenConstraints.optional = optionalConstraints;
2018-10-19 01:03:11 +08:00
console.log('getScreenConstraints for Chrome returns => ', screenConstraints);
return callback(null, screenConstraints);
}
2018-10-19 01:03:11 +08:00
2018-03-08 05:20:37 +08:00
if (isChrome) {
if (!hasDisplayMedia) {
const extensionKey = kurentoManager.getChromeExtensionKey();
getChromeScreenConstraints(extensionKey).then((constraints) => {
if (!constraints) {
document.dispatchEvent(new Event('installChromeExtension'));
return;
}
const sourceId = constraints.streamId;
kurentoManager.kurentoScreenshare.extensionInstalled = true;
// this statement sets gets 'sourceId" and sets "chromeMediaSourceId"
screenConstraints.video.chromeMediaSource = { exact: [sendSource] };
screenConstraints.video.chromeMediaSourceId = sourceId;
screenConstraints.optional = optionalConstraints;
console.log('getScreenConstraints for Chrome returns => ', screenConstraints);
return callback(null, screenConstraints);
});
} else {
return callback(null, getDisplayMediaConstraints());
}
}
if (isFirefox) {
const firefoxScreenshareSource = kurentoManager.getFirefoxScreenshareSource();
screenConstraints.video.mediaSource = firefoxScreenshareSource;
console.log('getScreenConstraints for Firefox returns => ', screenConstraints);
return callback(null, screenConstraints);
}
// Falls back to getDisplayMedia if the browser supports it
if (hasDisplayMedia) {
return callback(null, getDisplayMediaConstraints());
}
if (isSafari) {
// At this time (version 11.1), Safari doesn't support screenshare.
return document.dispatchEvent(new Event('safariScreenshareNotSupported'));
}
2018-03-08 05:20:37 +08:00
};
window.kurentoInitialize = function () {
2018-03-08 05:20:37 +08:00
if (window.kurentoManager == null || window.KurentoManager === undefined) {
window.kurentoManager = new KurentoManager();
}
};
2018-03-08 05:20:37 +08:00
window.kurentoShareScreen = function () {
window.kurentoInitialize();
window.kurentoManager.shareScreen.apply(window.kurentoManager, arguments);
};
window.kurentoExitScreenShare = function () {
window.kurentoInitialize();
window.kurentoManager.exitScreenShare();
};
window.kurentoWatchVideo = function () {
window.kurentoInitialize();
window.kurentoManager.joinWatchVideo.apply(window.kurentoManager, arguments);
};
window.kurentoExitVideo = function () {
window.kurentoInitialize();
window.kurentoManager.exitVideo();
2018-03-08 05:20:37 +08:00
};
window.kurentoJoinAudio = function () {
window.kurentoInitialize();
window.kurentoManager.joinAudio.apply(window.kurentoManager, arguments);
};
window.kurentoExitAudio = function () {
window.kurentoInitialize();
window.kurentoManager.exitAudio();
};
// a function to check whether the browser (Chrome only) is in an isIncognito
// session. Requires 1 mandatory callback that only gets called if the browser
// session is incognito. The callback for not being incognito is optional.
// Attempts to retrieve the chrome filesystem API.
/* window.checkIfIncognito = function(isIncognito, isNotIncognito = function () {}) {
isIncognito = Kurento.normalizeCallback(isIncognito);
isNotIncognito = Kurento.normalizeCallback(isNotIncognito);
var fs = window.RequestFileSystem || window.webkitRequestFileSystem;
if (!fs) {
isNotIncognito();
return;
}
fs(window.TEMPORARY, 100, function(){isNotIncognito()}, function(){isIncognito()});
};
window.checkChromeExtInstalled = function (callback, chromeExtensionId) {
callback = Kurento.normalizeCallback(callback);
if (typeof chrome === "undefined" || !chrome || !chrome.runtime) {
// No API, so no extension for sure
callback(false);
return;
}
chrome.runtime.sendMessage(
chromeExtensionId,
{ getVersion: true },
function (response) {
if (!response || !response.version) {
// Communication failure - assume that no endpoint exists
callback(false);
return;
}
callback(true);
}
);
2018-08-23 23:49:16 +08:00
} */