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 kurentoHandler = null;
|
2018-04-26 00:56:16 +08:00
|
|
|
const SEND_ROLE = "send";
|
|
|
|
const RECV_ROLE = "recv";
|
|
|
|
const SFU_APP = "screenshare";
|
|
|
|
const ON_ICE_CANDIDATE_MSG = "onIceCandidate";
|
|
|
|
const START_MSG = "start";
|
|
|
|
const START_RESPONSE_MSG = "startResponse";
|
2018-05-03 21:57:03 +08:00
|
|
|
const PING_INTERVAL = 15000;
|
2017-06-14 04:18:21 +08:00
|
|
|
|
|
|
|
Kurento = function (
|
2018-03-08 05:20:37 +08:00
|
|
|
tag,
|
|
|
|
voiceBridge,
|
|
|
|
conferenceUsername,
|
|
|
|
internalMeetingId,
|
|
|
|
onFail = null,
|
|
|
|
chromeExtension = null,
|
|
|
|
) {
|
2017-06-14 04:18:21 +08:00
|
|
|
this.ws = null;
|
2018-03-10 02:35:37 +08:00
|
|
|
this.video = null;
|
|
|
|
this.screen = null;
|
|
|
|
this.webRtcPeer = null;
|
2017-07-04 03:13:00 +08:00
|
|
|
this.mediaCallback = null;
|
2017-07-27 00:59:05 +08:00
|
|
|
|
2018-03-08 05:20:37 +08:00
|
|
|
this.voiceBridge = `${voiceBridge}-SCREENSHARE`;
|
2017-07-27 00:59:05 +08:00
|
|
|
this.internalMeetingId = internalMeetingId;
|
2017-06-14 04:18:21 +08:00
|
|
|
|
2018-03-10 02:35:37 +08:00
|
|
|
// Limiting max resolution to 1080p
|
|
|
|
// In FireFox we force full screen share and in the case
|
|
|
|
// of multiple screens the total area shared becomes too large
|
|
|
|
this.vid_max_width = 1920;
|
|
|
|
this.vid_max_height = 1080;
|
2017-06-14 04:18:21 +08:00
|
|
|
|
2017-07-18 03:30:58 +08:00
|
|
|
// TODO properly generate a uuid
|
2017-06-14 04:18:21 +08:00
|
|
|
this.sessid = Math.random().toString();
|
|
|
|
|
|
|
|
this.renderTag = 'remote-media';
|
|
|
|
|
|
|
|
this.caller_id_name = conferenceUsername;
|
|
|
|
this.caller_id_number = conferenceUsername;
|
|
|
|
|
2018-03-08 05:20:37 +08:00
|
|
|
this.kurentoPort = 'bbb-webrtc-sfu';
|
2017-06-14 04:18:21 +08:00
|
|
|
this.hostName = window.location.hostname;
|
2018-03-08 05:20:37 +08:00
|
|
|
this.socketUrl = `wss://${this.hostName}/${this.kurentoPort}`;
|
2018-05-03 21:57:03 +08:00
|
|
|
this.pingInterval = null;
|
2017-06-14 04:18:21 +08:00
|
|
|
|
|
|
|
this.iceServers = null;
|
|
|
|
|
|
|
|
if (chromeExtension != null) {
|
|
|
|
this.chromeExtension = chromeExtension;
|
2017-11-06 22:27:12 +08:00
|
|
|
window.chromeExtension = chromeExtension;
|
2017-06-14 04:18:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (onFail != null) {
|
2017-07-18 03:30:58 +08:00
|
|
|
this.onFail = Kurento.normalizeCallback(onFail);
|
2017-06-14 04:18:21 +08:00
|
|
|
} else {
|
2018-03-08 05:20:37 +08:00
|
|
|
const _this = this;
|
2017-06-14 04:18:21 +08:00
|
|
|
this.onFail = function () {
|
|
|
|
_this.logError('Default error handler');
|
|
|
|
};
|
|
|
|
}
|
2018-05-03 21:57:03 +08:00
|
|
|
|
2017-06-14 04:18:21 +08:00
|
|
|
};
|
|
|
|
|
2018-03-08 05:20:37 +08:00
|
|
|
this.KurentoManager = function () {
|
2017-06-14 04:18:21 +08:00
|
|
|
this.kurentoVideo = null;
|
2017-11-06 22:27:12 +08:00
|
|
|
this.kurentoScreenshare = null;
|
2017-06-14 04:18:21 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
KurentoManager.prototype.exitScreenShare = function () {
|
2018-03-08 05:20:37 +08:00
|
|
|
console.log(' [exitScreenShare] Exiting screensharing');
|
|
|
|
if (typeof this.kurentoScreenshare !== 'undefined' && this.kurentoScreenshare) {
|
|
|
|
if (this.kurentoScreenshare.ws !== null) {
|
|
|
|
this.kurentoScreenshare.ws.onclose = function () {};
|
2017-11-06 22:27:12 +08:00
|
|
|
this.kurentoScreenshare.ws.close();
|
2017-07-04 03:13:00 +08:00
|
|
|
}
|
2017-11-06 22:27:12 +08:00
|
|
|
|
2018-05-03 21:57:03 +08:00
|
|
|
if (this.kurentoScreenshare.pingInterval) {
|
|
|
|
clearInterval(this.kurentoScreenshare.pingInterval);
|
|
|
|
}
|
2017-11-06 22:27:12 +08:00
|
|
|
|
2018-05-03 21:57:03 +08:00
|
|
|
this.kurentoScreenshare.disposeScreenShare();
|
2017-11-06 22:27:12 +08:00
|
|
|
this.kurentoScreenshare = null;
|
|
|
|
}
|
|
|
|
|
2018-03-08 05:20:37 +08:00
|
|
|
if (typeof this.kurentoVideo !== 'undefined' && this.kurentoVideo) {
|
2017-11-06 22:27:12 +08:00
|
|
|
this.exitVideo();
|
2017-06-14 04:18:21 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-09-09 01:00:00 +08:00
|
|
|
KurentoManager.prototype.exitVideo = function () {
|
2018-03-08 05:20:37 +08:00
|
|
|
console.log(' [exitScreenShare] Exiting screensharing viewing');
|
|
|
|
if (typeof this.kurentoVideo !== 'undefined' && this.kurentoVideo) {
|
|
|
|
if (this.kurentoVideo.ws !== null) {
|
|
|
|
this.kurentoVideo.ws.onclose = function () {};
|
2017-11-06 22:27:12 +08:00
|
|
|
this.kurentoVideo.ws.close();
|
|
|
|
}
|
|
|
|
|
2018-05-03 21:57:03 +08:00
|
|
|
if (this.kurentoVideo.pingInterval) {
|
|
|
|
clearInterval(this.kurentoVideo.pingInterval);
|
|
|
|
}
|
2017-11-06 22:27:12 +08:00
|
|
|
|
2018-05-03 21:57:03 +08:00
|
|
|
this.kurentoVideo.disposeScreenShare();
|
2017-11-06 22:27:12 +08:00
|
|
|
this.kurentoVideo = null;
|
|
|
|
}
|
2017-09-09 01:00:00 +08:00
|
|
|
};
|
|
|
|
|
2017-06-14 04:18:21 +08:00
|
|
|
KurentoManager.prototype.shareScreen = function (tag) {
|
|
|
|
this.exitScreenShare();
|
2018-03-08 05:20:37 +08:00
|
|
|
const obj = Object.create(Kurento.prototype);
|
2017-06-14 04:18:21 +08:00
|
|
|
Kurento.apply(obj, arguments);
|
2017-11-06 22:27:12 +08:00
|
|
|
this.kurentoScreenshare = obj;
|
2018-04-26 00:56:16 +08:00
|
|
|
this.kurentoScreenshare.setScreensharing(tag);
|
2017-06-14 04:18:21 +08:00
|
|
|
};
|
|
|
|
|
2017-07-04 03:13:00 +08:00
|
|
|
KurentoManager.prototype.joinWatchVideo = function (tag) {
|
|
|
|
this.exitVideo();
|
2018-03-08 05:20:37 +08:00
|
|
|
const obj = Object.create(Kurento.prototype);
|
2017-07-04 03:13:00 +08:00
|
|
|
Kurento.apply(obj, arguments);
|
|
|
|
this.kurentoVideo = obj;
|
|
|
|
this.kurentoVideo.setWatchVideo(tag);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-04-26 00:56:16 +08:00
|
|
|
Kurento.prototype.setScreensharing = function (tag) {
|
|
|
|
this.mediaCallback = this.startScreensharing.bind(this);
|
2017-06-14 04:18:21 +08:00
|
|
|
this.create(tag);
|
|
|
|
};
|
|
|
|
|
|
|
|
Kurento.prototype.create = function (tag) {
|
|
|
|
this.setRenderTag(tag);
|
|
|
|
this.iceServers = true;
|
|
|
|
this.init();
|
|
|
|
};
|
|
|
|
|
|
|
|
Kurento.prototype.init = function () {
|
2018-03-08 05:20:37 +08:00
|
|
|
const self = this;
|
|
|
|
if ('WebSocket' in window) {
|
|
|
|
console.log('this browser supports websockets');
|
2017-06-14 04:18:21 +08:00
|
|
|
this.ws = new WebSocket(this.socketUrl);
|
|
|
|
|
2017-11-06 22:27:12 +08:00
|
|
|
this.ws.onmessage = this.onWSMessage.bind(this);
|
|
|
|
this.ws.onclose = (close) => {
|
2017-07-06 01:58:19 +08:00
|
|
|
kurentoManager.exitScreenShare();
|
2018-03-08 05:20:37 +08:00
|
|
|
self.onFail('Websocket connection closed');
|
2017-06-14 04:18:21 +08:00
|
|
|
};
|
2017-11-06 22:27:12 +08:00
|
|
|
this.ws.onerror = (error) => {
|
2017-07-06 01:58:19 +08:00
|
|
|
kurentoManager.exitScreenShare();
|
2018-03-08 05:20:37 +08:00
|
|
|
self.onFail('Websocket connection error');
|
2017-06-14 04:18:21 +08:00
|
|
|
};
|
2017-11-06 22:27:12 +08:00
|
|
|
this.ws.onopen = function () {
|
2018-05-03 21:57:03 +08:00
|
|
|
self.pingInterval = setInterval(self.ping.bind(self), PING_INTERVAL);
|
2017-07-04 03:13:00 +08:00
|
|
|
self.mediaCallback();
|
2018-03-08 05:20:37 +08:00
|
|
|
};
|
|
|
|
} else { console.log('this browser does not support websockets'); }
|
2017-06-14 04:18:21 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
Kurento.prototype.onWSMessage = function (message) {
|
2018-03-08 05:20:37 +08:00
|
|
|
const parsedMessage = JSON.parse(message.data);
|
2017-06-14 04:18:21 +08:00
|
|
|
switch (parsedMessage.id) {
|
2018-04-26 00:56:16 +08:00
|
|
|
case 'startResponse':
|
|
|
|
this.startResponse(parsedMessage);
|
2017-09-09 01:00:00 +08:00
|
|
|
break;
|
2017-06-14 04:18:21 +08:00
|
|
|
case 'stopSharing':
|
2017-07-11 04:51:37 +08:00
|
|
|
kurentoManager.exitScreenShare();
|
2017-06-14 04:18:21 +08:00
|
|
|
break;
|
|
|
|
case 'iceCandidate':
|
2017-11-06 22:27:12 +08:00
|
|
|
this.webRtcPeer.addIceCandidate(parsedMessage.candidate);
|
2017-07-04 03:13:00 +08:00
|
|
|
break;
|
2018-05-03 21:57:03 +08:00
|
|
|
case 'pong':
|
|
|
|
break;
|
2017-06-14 04:18:21 +08:00
|
|
|
default:
|
|
|
|
console.error('Unrecognized message', parsedMessage);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Kurento.prototype.setRenderTag = function (tag) {
|
|
|
|
this.renderTag = tag;
|
|
|
|
};
|
|
|
|
|
2018-04-26 00:56:16 +08:00
|
|
|
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';
|
|
|
|
console.warn(`Call not accepted for the following reason: ${errorMsg}`);
|
2017-11-06 22:27:12 +08:00
|
|
|
kurentoManager.exitScreenShare();
|
2017-06-14 04:18:21 +08:00
|
|
|
} else {
|
2018-04-26 00:56:16 +08:00
|
|
|
console.debug(`Screenshare procedure was accepted with SDP => ${message.sdpAnswer}`);
|
2017-06-14 04:18:21 +08:00
|
|
|
this.webRtcPeer.processAnswer(message.sdpAnswer);
|
|
|
|
}
|
2018-03-08 05:20:37 +08:00
|
|
|
};
|
2017-06-14 04:18:21 +08:00
|
|
|
|
|
|
|
Kurento.prototype.onOfferPresenter = function (error, offerSdp) {
|
2018-03-08 05:20:37 +08:00
|
|
|
const self = this;
|
|
|
|
if (error) {
|
|
|
|
console.log(`Kurento.prototype.onOfferPresenter Error ${error}`);
|
2017-11-06 22:27:12 +08:00
|
|
|
this.onFail(error);
|
2017-06-14 04:18:21 +08:00
|
|
|
return;
|
|
|
|
}
|
2017-07-18 03:30:58 +08:00
|
|
|
|
2018-03-08 05:20:37 +08:00
|
|
|
const message = {
|
2018-04-26 00:56:16 +08:00
|
|
|
id: 'start',
|
|
|
|
type: SFU_APP,
|
|
|
|
role: SEND_ROLE,
|
2017-11-06 22:27:12 +08:00
|
|
|
internalMeetingId: self.internalMeetingId,
|
|
|
|
voiceBridge: self.voiceBridge,
|
2018-03-08 05:20:37 +08:00
|
|
|
callerName: self.caller_id_name,
|
|
|
|
sdpOffer: offerSdp,
|
2018-03-10 02:35:37 +08:00
|
|
|
vh: self.vid_max_height,
|
|
|
|
vw: self.vid_max_width,
|
2017-06-14 04:18:21 +08:00
|
|
|
};
|
2018-04-26 00:56:16 +08:00
|
|
|
|
2018-03-08 05:20:37 +08:00
|
|
|
console.log(`onOfferPresenter sending to screenshare server => ${JSON.stringify(message, null, 2)}`);
|
2017-11-06 22:27:12 +08:00
|
|
|
this.sendMessage(message);
|
2018-03-08 05:20:37 +08:00
|
|
|
};
|
2017-06-14 04:18:21 +08:00
|
|
|
|
2018-04-26 00:56:16 +08:00
|
|
|
Kurento.prototype.startScreensharing = function () {
|
2018-03-08 05:20:37 +08:00
|
|
|
if (window.chrome) {
|
2018-04-26 00:56:16 +08:00
|
|
|
if (!this.chromeExtension) {
|
|
|
|
this.logError({
|
2018-03-08 05:20:37 +08:00
|
|
|
status: 'failed',
|
2017-06-14 04:18:21 +08:00
|
|
|
message: 'Missing Chrome Extension key',
|
|
|
|
});
|
2018-04-26 00:56:16 +08:00
|
|
|
this.onFail();
|
2017-06-14 04:18:21 +08:00
|
|
|
return;
|
|
|
|
}
|
2017-07-04 03:13:00 +08:00
|
|
|
}
|
|
|
|
|
2018-03-08 05:20:37 +08:00
|
|
|
const options = {
|
2017-11-06 22:27:12 +08:00
|
|
|
localVideo: document.getElementById(this.renderTag),
|
2018-04-26 00:56:16 +08:00
|
|
|
onicecandidate: (candidate) => {
|
|
|
|
this.onIceCandidate(candidate, SEND_ROLE);
|
|
|
|
},
|
2018-03-08 05:20:37 +08:00
|
|
|
sendSource: 'desktop',
|
2017-07-04 03:13:00 +08:00
|
|
|
};
|
2017-06-14 04:18:21 +08:00
|
|
|
|
2018-03-08 05:20:37 +08:00
|
|
|
console.log(` Peer options => ${JSON.stringify(options, null, 2)}`);
|
2017-06-14 04:18:21 +08:00
|
|
|
|
2018-04-26 00:56:16 +08:00
|
|
|
this.webRtcPeer = kurentoUtils.WebRtcPeer.WebRtcPeerSendonly(options, (error) => {
|
2018-03-08 05:20:37 +08:00
|
|
|
if (error) {
|
|
|
|
console.log(`WebRtcPeerSendonly constructor error ${JSON.stringify(error, null, 2)}`);
|
2018-04-26 00:56:16 +08:00
|
|
|
this.onFail(error);
|
2017-07-04 03:13:00 +08:00
|
|
|
return kurentoManager.exitScreenShare();
|
|
|
|
}
|
2017-07-18 03:30:58 +08:00
|
|
|
|
2018-04-26 00:56:16 +08:00
|
|
|
this.webRtcPeer.generateOffer(this.onOfferPresenter.bind(this));
|
2018-03-08 05:20:37 +08:00
|
|
|
console.log(`Generated peer offer w/ options ${JSON.stringify(options)}`);
|
|
|
|
|
2018-04-26 00:56:16 +08:00
|
|
|
const localStream = this.webRtcPeer.peerConnection.getLocalStreams()[0];
|
2018-03-08 05:20:37 +08:00
|
|
|
localStream.getVideoTracks()[0].onended = function () {
|
|
|
|
return kurentoManager.exitScreenShare();
|
|
|
|
};
|
|
|
|
|
|
|
|
localStream.getVideoTracks()[0].oninactive = function () {
|
|
|
|
return kurentoManager.exitScreenShare();
|
|
|
|
};
|
2017-07-04 03:13:00 +08:00
|
|
|
});
|
2018-03-08 05:20:37 +08:00
|
|
|
};
|
2017-06-14 04:18:21 +08:00
|
|
|
|
2018-04-26 00:56:16 +08:00
|
|
|
Kurento.prototype.onIceCandidate = function (candidate, role) {
|
2018-03-08 05:20:37 +08:00
|
|
|
const self = this;
|
|
|
|
console.log(`Local candidate${JSON.stringify(candidate)}`);
|
2017-06-14 04:18:21 +08:00
|
|
|
|
2018-03-08 05:20:37 +08:00
|
|
|
const message = {
|
2018-04-26 00:56:16 +08:00
|
|
|
id: ON_ICE_CANDIDATE_MSG,
|
|
|
|
role: role,
|
|
|
|
type: SFU_APP,
|
2017-11-06 22:27:12 +08:00
|
|
|
voiceBridge: self.voiceBridge,
|
2018-03-08 05:20:37 +08:00
|
|
|
candidate,
|
|
|
|
callerName: self.caller_id_name,
|
|
|
|
};
|
2018-04-26 00:56:16 +08:00
|
|
|
|
2017-11-06 22:27:12 +08:00
|
|
|
this.sendMessage(message);
|
2018-03-08 05:20:37 +08:00
|
|
|
};
|
2017-09-09 01:00:00 +08:00
|
|
|
|
2017-07-04 03:13:00 +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;
|
2017-07-04 03:13:00 +08:00
|
|
|
if (!this.webRtcPeer) {
|
2018-03-08 05:20:37 +08:00
|
|
|
const options = {
|
2018-04-13 02:25:51 +08:00
|
|
|
mediaConstraints: {
|
|
|
|
audio: false
|
|
|
|
},
|
2017-09-09 01:00:00 +08:00
|
|
|
remoteVideo: document.getElementById(this.renderTag),
|
2018-04-26 00:56:16 +08:00
|
|
|
onicecandidate: (candidate) => {
|
|
|
|
this.onIceCandidate(candidate, RECV_ROLE);
|
|
|
|
}
|
|
|
|
}
|
2017-07-04 03:13:00 +08:00
|
|
|
|
2018-03-08 05:20:37 +08:00
|
|
|
self.webRtcPeer = kurentoUtils.WebRtcPeer.WebRtcPeerRecvonly(options, function (error) {
|
|
|
|
if (error) {
|
2017-11-06 22:27:12 +08:00
|
|
|
return self.onFail(error);
|
2017-07-18 03:30:58 +08:00
|
|
|
}
|
2017-07-04 03:13:00 +08:00
|
|
|
|
2017-11-06 22:27:12 +08:00
|
|
|
this.generateOffer(self.onOfferViewer.bind(self));
|
2017-07-04 03:13:00 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Kurento.prototype.onOfferViewer = function (error, offerSdp) {
|
2018-03-08 05:20:37 +08:00
|
|
|
const self = this;
|
|
|
|
if (error) {
|
|
|
|
console.log(`Kurento.prototype.onOfferViewer Error ${error}`);
|
2017-11-06 22:27:12 +08:00
|
|
|
return this.onFail();
|
2017-07-04 03:13:00 +08:00
|
|
|
}
|
2018-03-08 05:20:37 +08:00
|
|
|
const message = {
|
2018-04-26 00:56:16 +08:00
|
|
|
id: 'start',
|
|
|
|
type: SFU_APP,
|
|
|
|
role: RECV_ROLE,
|
2017-11-06 22:27:12 +08:00
|
|
|
internalMeetingId: self.internalMeetingId,
|
|
|
|
voiceBridge: self.voiceBridge,
|
2018-03-08 05:20:37 +08:00
|
|
|
callerName: self.caller_id_name,
|
|
|
|
sdpOffer: offerSdp,
|
2017-07-04 03:13:00 +08:00
|
|
|
};
|
|
|
|
|
2018-03-08 05:20:37 +08:00
|
|
|
console.log(`onOfferViewer sending to screenshare server => ${JSON.stringify(message, null, 2)}`);
|
2017-11-06 22:27:12 +08:00
|
|
|
this.sendMessage(message);
|
2017-07-04 03:13:00 +08:00
|
|
|
};
|
|
|
|
|
2018-04-26 00:56:16 +08:00
|
|
|
Kurento.prototype.pauseTrack = function (message) {
|
|
|
|
const localStream = this.webRtcPeer.peerConnection.getLocalStreams()[0];
|
|
|
|
const track = localStream.getVideoTracks()[0];
|
|
|
|
|
|
|
|
if (track) {
|
|
|
|
track.enabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Kurento.prototype.resumeTrack = function (message) {
|
|
|
|
const localStream = this.webRtcPeer.peerConnection.getLocalStreams()[0];
|
|
|
|
const track = localStream.getVideoTracks()[0];
|
|
|
|
|
|
|
|
if (track) {
|
|
|
|
track.enabled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-08 05:20:37 +08:00
|
|
|
Kurento.prototype.stop = function () {
|
|
|
|
// if (this.webRtcPeer) {
|
2017-11-06 22:27:12 +08:00
|
|
|
// var message = {
|
|
|
|
// id : 'stop',
|
|
|
|
// type : 'screenshare',
|
|
|
|
// voiceBridge: kurentoHandler.voiceBridge
|
|
|
|
// }
|
|
|
|
// kurentoHandler.sendMessage(message);
|
|
|
|
// kurentoHandler.disposeScreenShare();
|
2018-03-08 05:20:37 +08:00
|
|
|
// }
|
|
|
|
};
|
2017-06-14 04:18:21 +08:00
|
|
|
|
2018-03-08 05:20:37 +08:00
|
|
|
Kurento.prototype.dispose = function () {
|
2017-06-14 04:18:21 +08:00
|
|
|
if (this.webRtcPeer) {
|
|
|
|
this.webRtcPeer.dispose();
|
|
|
|
this.webRtcPeer = null;
|
|
|
|
}
|
2018-03-08 05:20:37 +08:00
|
|
|
};
|
2017-06-14 04:18:21 +08:00
|
|
|
|
2018-03-08 05:20:37 +08:00
|
|
|
Kurento.prototype.disposeScreenShare = function () {
|
2017-06-14 04:18:21 +08:00
|
|
|
if (this.webRtcPeer) {
|
|
|
|
this.webRtcPeer.dispose();
|
|
|
|
this.webRtcPeer = null;
|
|
|
|
}
|
2018-03-08 05:20:37 +08:00
|
|
|
};
|
2017-06-14 04:18:21 +08:00
|
|
|
|
2018-05-03 21:57:03 +08:00
|
|
|
Kurento.prototype.ping = function () {
|
|
|
|
const message = {
|
|
|
|
id: 'ping'
|
|
|
|
};
|
|
|
|
this.sendMessage(message);
|
|
|
|
}
|
|
|
|
|
2018-03-08 05:20:37 +08:00
|
|
|
Kurento.prototype.sendMessage = function (message) {
|
|
|
|
const jsonMessage = JSON.stringify(message);
|
|
|
|
console.log(`Sending message: ${jsonMessage}`);
|
2017-06-14 04:18:21 +08:00
|
|
|
this.ws.send(jsonMessage);
|
2018-03-08 05:20:37 +08:00
|
|
|
};
|
2017-06-14 04:18:21 +08:00
|
|
|
|
|
|
|
Kurento.prototype.logger = function (obj) {
|
|
|
|
console.log(obj);
|
|
|
|
};
|
|
|
|
|
|
|
|
Kurento.prototype.logError = function (obj) {
|
|
|
|
console.error(obj);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-07-18 03:30:58 +08:00
|
|
|
Kurento.normalizeCallback = function (callback) {
|
2018-03-08 05:20:37 +08:00
|
|
|
if (typeof callback === 'function') {
|
2017-07-18 03:30:58 +08:00
|
|
|
return callback;
|
|
|
|
}
|
2018-03-08 05:20:37 +08:00
|
|
|
console.log(document.getElementById('BigBlueButton')[callback]);
|
|
|
|
return function (args) {
|
|
|
|
document.getElementById('BigBlueButton')[callback](args);
|
|
|
|
};
|
2017-07-18 03:30:58 +08:00
|
|
|
};
|
2017-06-14 04:18:21 +08:00
|
|
|
|
|
|
|
/* Global methods */
|
|
|
|
|
2017-07-04 03:13:00 +08:00
|
|
|
// this function explains how to use above methods/objects
|
2018-03-08 05:20:37 +08:00
|
|
|
window.getScreenConstraints = function (sendSource, callback) {
|
2018-04-13 02:25:51 +08:00
|
|
|
const screenConstraints = { video: {}, audio: false };
|
2017-07-04 03:13:00 +08:00
|
|
|
|
2018-02-09 06:53:18 +08:00
|
|
|
// 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-02-09 06:53:18 +08:00
|
|
|
|
2018-03-10 02:35:37 +08:00
|
|
|
screenConstraints.video.height = { max: this.vid_max_height };
|
|
|
|
screenConstraints.video.width = { max: this.vid_max_width };
|
2018-02-09 06:53:18 +08:00
|
|
|
|
2018-03-08 05:20:37 +08:00
|
|
|
if (isChrome) {
|
|
|
|
getChromeScreenConstraints((constraints) => {
|
2018-02-09 06:53:18 +08:00
|
|
|
if (!constraints) {
|
2018-03-08 05:20:37 +08:00
|
|
|
document.dispatchEvent(new Event('installChromeExtension'));
|
2018-01-06 01:13:22 +08:00
|
|
|
return;
|
|
|
|
}
|
2018-02-09 06:53:18 +08:00
|
|
|
|
2018-03-08 05:20:37 +08:00
|
|
|
const sourceId = constraints.streamId;
|
2017-07-04 03:13:00 +08:00
|
|
|
|
2018-02-09 06:53:18 +08:00
|
|
|
kurentoManager.kurentoScreenshare.extensionInstalled = true;
|
|
|
|
|
2017-07-04 03:13:00 +08:00
|
|
|
// this statement sets gets 'sourceId" and sets "chromeMediaSourceId"
|
2018-03-08 05:20:37 +08:00
|
|
|
screenConstraints.video.chromeMediaSource = { exact: [sendSource] };
|
2017-11-06 22:27:12 +08:00
|
|
|
screenConstraints.video.chromeMediaSourceId = sourceId;
|
2018-04-17 23:23:25 +08:00
|
|
|
screenConstraints.optional = [
|
|
|
|
{ googCpuOveruseDetection: true },
|
|
|
|
{ googCpuOveruseEncodeUsage: true },
|
|
|
|
{ googCpuUnderuseThreshold: 55 },
|
2018-04-27 22:37:18 +08:00
|
|
|
{ googCpuOveruseThreshold: 100},
|
2018-04-17 23:23:25 +08:00
|
|
|
{ googPayloadPadding: true },
|
2018-04-27 22:37:18 +08:00
|
|
|
{ googScreencastMinBitrate: 600 },
|
2018-04-17 23:23:25 +08:00
|
|
|
{ googHighStartBitrate: true },
|
|
|
|
{ googHighBitrate: true },
|
|
|
|
{ googVeryHighBitrate: true }
|
|
|
|
];
|
2018-02-09 06:53:18 +08:00
|
|
|
|
2018-03-10 02:35:37 +08:00
|
|
|
console.log('getScreenConstraints for Chrome returns => ', screenConstraints);
|
2017-07-04 03:13:00 +08:00
|
|
|
// now invoking native getUserMedia API
|
2017-11-06 22:27:12 +08:00
|
|
|
callback(null, screenConstraints);
|
|
|
|
}, chromeExtension);
|
2018-03-08 05:20:37 +08:00
|
|
|
} else if (isFirefox) {
|
|
|
|
screenConstraints.video.mediaSource = 'screen';
|
2017-11-06 22:27:12 +08:00
|
|
|
|
2018-03-10 02:35:37 +08:00
|
|
|
console.log('getScreenConstraints for Firefox returns => ', screenConstraints);
|
2017-11-06 22:27:12 +08:00
|
|
|
// now invoking native getUserMedia API
|
|
|
|
callback(null, screenConstraints);
|
2018-03-08 05:20:37 +08:00
|
|
|
} else if (isSafari) {
|
|
|
|
screenConstraints.video.mediaSource = 'screen';
|
2017-07-04 03:13:00 +08:00
|
|
|
|
2018-03-10 02:35:37 +08:00
|
|
|
console.log('getScreenConstraints for Safari returns => ', screenConstraints);
|
2017-07-04 03:13:00 +08:00
|
|
|
// now invoking native getUserMedia API
|
2017-11-06 22:27:12 +08:00
|
|
|
callback(null, screenConstraints);
|
2017-07-04 03:13:00 +08:00
|
|
|
}
|
2018-03-08 05:20:37 +08:00
|
|
|
};
|
2017-07-04 03:13:00 +08:00
|
|
|
|
|
|
|
window.kurentoInitialize = function () {
|
2018-03-08 05:20:37 +08:00
|
|
|
if (window.kurentoManager == null || window.KurentoManager === undefined) {
|
2017-07-04 03:13:00 +08:00
|
|
|
window.kurentoManager = new KurentoManager();
|
|
|
|
}
|
2017-06-14 04:18:21 +08:00
|
|
|
};
|
|
|
|
|
2018-03-08 05:20:37 +08:00
|
|
|
window.kurentoShareScreen = function () {
|
2017-07-04 03:13:00 +08:00
|
|
|
window.kurentoInitialize();
|
|
|
|
window.kurentoManager.shareScreen.apply(window.kurentoManager, arguments);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-06-14 04:18:21 +08:00
|
|
|
window.kurentoExitScreenShare = function () {
|
|
|
|
window.kurentoInitialize();
|
|
|
|
window.kurentoManager.exitScreenShare();
|
|
|
|
};
|
|
|
|
|
2017-07-04 03:13:00 +08:00
|
|
|
window.kurentoWatchVideo = function () {
|
|
|
|
window.kurentoInitialize();
|
|
|
|
window.kurentoManager.joinWatchVideo.apply(window.kurentoManager, arguments);
|
|
|
|
};
|
2017-09-09 01:00:00 +08:00
|
|
|
|
|
|
|
window.kurentoExitVideo = function () {
|
2017-11-06 22:27:12 +08:00
|
|
|
window.kurentoInitialize();
|
|
|
|
window.kurentoManager.exitVideo();
|
2018-03-08 05:20:37 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
window.getChromeScreenConstraints = function (callback, extensionId) {
|
|
|
|
chrome.runtime.sendMessage(
|
|
|
|
extensionId, {
|
|
|
|
getStream: true,
|
|
|
|
sources: [
|
|
|
|
'window',
|
|
|
|
'screen',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
(response) => {
|
2017-11-06 22:27:12 +08:00
|
|
|
console.log(response);
|
|
|
|
callback(response);
|
2018-03-08 05:20:37 +08:00
|
|
|
},
|
|
|
|
);
|
|
|
|
};
|
2018-04-20 05:45:22 +08:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|