bigbluebutton-Github/bigbluebutton-client/resources/prod/lib/verto_extension.js

657 lines
18 KiB
JavaScript
Raw Normal View History

2016-06-09 04:07:43 +08:00
Verto = function (
2016-06-18 04:36:45 +08:00
tag,
2016-06-09 04:07:43 +08:00
voiceBridge,
conferenceUsername,
userCallback,
2016-06-18 04:36:45 +08:00
onFail = null,
chromeExtension = null) {
2016-06-09 04:07:43 +08:00
voiceBridge += "-DESKSHARE";
2016-06-09 04:07:43 +08:00
this.cur_call = null;
this.share_call = null;
this.vertoHandle;
2016-10-07 00:16:07 +08:00
this.vid_width = window.screen.width;
this.vid_height = window.screen.height;
2016-06-09 04:07:43 +08:00
this.outgoingBandwidth = "default";
this.incomingBandwidth = "default";
2016-09-15 04:25:31 +08:00
this.sessid = $.verto.genUUID();
2016-06-09 04:07:43 +08:00
2016-06-20 23:59:48 +08:00
this.renderTag = 'remote-media';
2016-06-09 04:07:43 +08:00
this.destination_number = voiceBridge;
this.caller_id_name = conferenceUsername;
this.caller_id_number = conferenceUsername;
2017-03-23 06:20:15 +08:00
this.vertoPort = "verto";
2016-08-06 02:42:02 +08:00
this.hostName = window.location.hostname;
2017-03-23 06:20:15 +08:00
this.socketUrl = 'wss://' + this.hostName + '/' + this.vertoPort;
2016-08-06 02:42:02 +08:00
this.login = "bbbuser";
this.password = "secret";
2016-06-09 04:07:43 +08:00
this.useVideo = false;
this.useCamera = false;
this.useMic = false;
this.callWasSuccessful = false;
this.iceServers = null;
this.userCallback = userCallback;
2016-06-17 23:43:03 +08:00
if (chromeExtension != null) {
this.chromeExtension = chromeExtension;
}
2016-06-18 04:36:45 +08:00
if (onFail != null) {
this.onFail = Verto.normalizeCallback(onFail);
2016-06-21 03:39:20 +08:00
} else {
var _this = this;
this.onFail = function () {
_this.logError('Default error handler');
};
2016-06-18 04:36:45 +08:00
}
2016-06-09 04:07:43 +08:00
};
2016-06-20 23:59:48 +08:00
Verto.prototype.logger = function (obj) {
2016-06-09 04:07:43 +08:00
console.log(obj);
};
2016-06-20 23:59:48 +08:00
Verto.prototype.logError = function (obj) {
2016-06-09 04:07:43 +08:00
console.error(obj);
};
2016-06-20 23:59:48 +08:00
Verto.prototype.setRenderTag = function (tag) {
2016-06-09 04:07:43 +08:00
this.renderTag = tag;
};
2015-07-10 23:13:13 +08:00
2016-02-24 07:16:39 +08:00
// receives either a string variable holding the name of an actionscript
// registered callback, or a javascript function object.
// The function will return either the function if it is a javascript Function
// or if it is an actionscript string it will return a javascript Function
// that when invokved will invoke the actionscript registered callback
// and passes along parameters
Verto.normalizeCallback = function (callback) {
2016-06-20 23:59:48 +08:00
if (typeof callback == 'function') {
2016-06-09 04:07:43 +08:00
return callback;
} else {
2016-06-20 23:59:48 +08:00
return function (args) {
document.getElementById('BigBlueButton')[callback](args);
2016-06-09 04:07:43 +08:00
};
}
};
2016-06-20 23:59:48 +08:00
Verto.prototype.onWSLogin = function (v, success) {
2016-06-09 04:07:43 +08:00
this.cur_call = null;
if (success) {
this.callWasSuccessful = true;
2016-06-15 00:11:04 +08:00
this.mediaCallback();
2016-06-18 04:36:45 +08:00
return;
2016-06-09 04:07:43 +08:00
} else {
2016-06-21 03:39:20 +08:00
// error logging verto into freeswitch
2016-06-20 23:59:48 +08:00
this.logError({ status: 'failed', errorcode: '10XX' });
2016-06-18 04:36:45 +08:00
this.callWasSuccessful = false;
this.onFail();
return;
2016-06-09 04:07:43 +08:00
}
};
2016-06-15 00:11:04 +08:00
Verto.prototype.registerCallbacks = function () {
2016-06-09 04:07:43 +08:00
var callbacks = {
2016-12-02 01:00:15 +08:00
onMessage: function (verto, dialog, msg, data) {
switch (msg) {
case $.verto.enum.message.pvtEvent:
if (data.pvtData) {
switch (data.pvtData.action) {
// This client has joined the live array for the conference.
case "conference-liveArray-join":
initLiveArray(verto, dialog, data);
break;
// This client has left the live array for the conference.
case "conference-liveArray-part":
// Some kind of client-side wrapup...
break;
}
}
break;
}
},
2016-06-20 23:59:48 +08:00
onDialogState: function (d) {},
2016-06-09 04:07:43 +08:00
onWSLogin: this.onWSLogin.bind(this),
2016-06-20 23:59:48 +08:00
onWSClose: function (v, success) {
2016-06-09 04:07:43 +08:00
cur_call = null;
if (this.callWasSuccessful) {
// the connection was dropped in an already established call
this.logError('websocket disconnected');
2016-06-20 23:59:48 +08:00
2016-06-09 04:07:43 +08:00
// WebSocket disconnected
2016-06-20 23:59:48 +08:00
this.logError({ status: 'failed', errorcode: 1001 });
2016-06-09 04:07:43 +08:00
toDisplayDisconnectCallback = false;
} else {
// this callback was triggered and a call was never successfully established
2016-06-20 23:59:48 +08:00
this.logError('websocket connection could not be established');
2016-06-09 04:07:43 +08:00
// Could not make a WebSocket connection
2016-06-20 23:59:48 +08:00
this.logError({ status: 'failed', errorcode: 1002 });
2016-06-18 04:36:45 +08:00
this.onFail();
return;
2016-06-09 04:07:43 +08:00
}
}.bind(this),
};
this.callbacks = callbacks;
};
2016-12-02 01:00:15 +08:00
var initLiveArray = function(verto, dialog, data) {
// Set up addtional configuration specific to the call.
window.vertoConf = new $.verto.conf(verto, {
dialog: dialog,
hasVid: true,
laData: data.pvtData,
// For subscribing to published chat messages.
chatCallback: function(verto, eventObj) {
var from = eventObj.data.fromDisplay || eventObj.data.from || 'Unknown';
var message = eventObj.data.message || '';
},
});
var config = {
subParams: {
callID: dialog ? dialog.callID : null
},
};
// Set up the live array, using the live array data received from FreeSWITCH.
window.liveArray = new $.verto.liveArray(window.vertoHandle, data.pvtData.laChannel, data.pvtData.laName, config);
// Subscribe to live array changes.
window.liveArray.onChange = function(liveArrayObj, args) {
console.log("Call UUID is: " + args.key);
console.log("Call data is: ", args.data);
console.log(liveArrayObj);
console.log(args);
try {
switch (args.action) {
// Initial list of existing conference users.
case "bootObj":
break;
// New user joined conference.
case "add":
break;
// User left conference.
case "del":
break;
// Existing user's state changed (mute/unmute, talking, floor, etc)
case "modify":
break;
}
} catch (err) {
console.error("ERROR: " + err);
}
};
// Called if the live array throws an error.
window.liveArray.onErr = function (obj, args) {
console.error("Error: ", obj, args);
};
};
2016-06-09 04:07:43 +08:00
Verto.prototype.hold = function () {
this.cur_call.toggleHold();
};
Verto.prototype.hangup = function () {
if (this.cur_call) {
// the duration of the call
this.logger('call ended ' + this.cur_call.audioStream.currentTime);
this.cur_call.hangup();
this.cur_call = null;
2016-06-09 04:07:43 +08:00
}
2016-06-15 00:11:04 +08:00
if (this.share_call) {
// the duration of the call
this.logger('call ended ' + this.share_call.audioStream.currentTime);
2016-10-06 03:57:09 +08:00
this.share_call.rtc.localStream.getTracks().forEach(track => track.stop());
this.share_call.hangup();
this.share_call = null;
2016-06-15 00:11:04 +08:00
}
2016-06-09 04:07:43 +08:00
// the user ended the call themself
// if (callPurposefullyEnded === true) {
if (true) {
2016-06-20 23:59:48 +08:00
this.logger({ status: 'ended' });
2016-06-09 04:07:43 +08:00
} else {
// Call ended unexpectedly
2016-06-20 23:59:48 +08:00
this.logError({ status: 'failed', errorcode: 1005 });
2016-06-09 04:07:43 +08:00
}
};
Verto.prototype.mute = function () {
2016-06-20 23:59:48 +08:00
this.cur_call.dtmf('0');
2016-06-09 04:07:43 +08:00
};
Verto.prototype.localmute = function () {
2016-06-20 23:59:48 +08:00
// var muted = cur_call.setMute('toggle');
2016-06-09 04:07:43 +08:00
// if (muted) {
2016-06-20 23:59:48 +08:00
// display('Talking to: ' + cur_call.cidString() + ' [LOCALLY MUTED]');
2016-06-09 04:07:43 +08:00
// } else {
2016-06-20 23:59:48 +08:00
// display('Talking to: ' + cur_call.cidString());
2016-06-09 04:07:43 +08:00
// }
};
Verto.prototype.localvidmute = function () {
2016-06-20 23:59:48 +08:00
// var muted = cur_call.setVideoMute('toggle');
2016-06-09 04:07:43 +08:00
// if (muted) {
2016-06-20 23:59:48 +08:00
// display('Talking to: ' + cur_call.cidString() + ' [VIDEO LOCALLY MUTED]');
2016-06-09 04:07:43 +08:00
// } else {
2016-06-20 23:59:48 +08:00
// display('Talking to: ' + cur_call.cidString());
2016-06-09 04:07:43 +08:00
// }
};
Verto.prototype.vmute = function () {
2016-06-20 23:59:48 +08:00
this.cur_call.dtmf('*0');
2016-06-09 04:07:43 +08:00
};
2016-06-20 23:59:48 +08:00
Verto.prototype.setWatchVideo = function (tag) {
2016-06-15 00:11:04 +08:00
this.mediaCallback = this.docall;
2016-06-09 04:07:43 +08:00
this.useVideo = true;
2017-02-23 04:31:09 +08:00
this.useCamera = 'none';
this.useMic = 'none';
2016-06-09 04:07:43 +08:00
this.create(tag);
};
2016-06-20 23:59:48 +08:00
Verto.prototype.setListenOnly = function (tag) {
2016-06-15 00:11:04 +08:00
this.mediaCallback = this.docall;
2016-06-09 04:07:43 +08:00
this.useVideo = false;
this.useCamera = 'none';
this.useMic = 'none';
this.create(tag);
};
2016-06-20 23:59:48 +08:00
Verto.prototype.setMicrophone = function (tag) {
2016-06-15 00:11:04 +08:00
this.mediaCallback = this.docall;
2016-06-09 04:07:43 +08:00
this.useVideo = false;
this.useCamera = 'none';
this.useMic = 'any';
this.create(tag);
};
2016-06-20 23:59:48 +08:00
Verto.prototype.setScreenShare = function (tag) {
2017-02-07 23:18:52 +08:00
// required for Verto to know we want to use video
// tell Verto we want to share webcam so it knows there will be a video stream
// but instead of a webcam we pass screen constraints
this.useCamera = 'any';
2016-06-17 23:43:03 +08:00
this.mediaCallback = this.makeShare;
2016-06-15 00:11:04 +08:00
this.create(tag);
};
2016-06-20 23:59:48 +08:00
Verto.prototype.create = function (tag) {
2016-06-09 04:07:43 +08:00
this.setRenderTag(tag);
this.registerCallbacks();
2016-08-19 22:07:47 +08:00
//this.configStuns(this.init);
this.iceServers = true;
this.init();
2016-06-09 04:07:43 +08:00
};
Verto.prototype.docall = function () {
if (this.cur_call) {
2016-06-20 23:59:48 +08:00
this.logger('Quitting: Call already in progress');
2016-06-09 04:07:43 +08:00
return;
}
2016-06-20 23:05:39 +08:00
this.cur_call = window.vertoHandle.newCall({
2016-06-09 04:07:43 +08:00
destination_number: this.destination_number,
caller_id_name: this.caller_id_name,
caller_id_number: this.caller_id_number,
outgoingBandwidth: this.outgoingBandwidth,
incomingBandwidth: this.incomingBandwidth,
useVideo: this.useVideo,
useStereo: true,
useCamera: this.useCamera,
useMic: this.useMic,
useSpeak: 'any',
dedEnc: true,
2016-06-20 23:05:39 +08:00
tag: this.renderTag,
2016-06-09 04:07:43 +08:00
});
this.logger(this.cur_call);
};
2016-06-17 23:43:03 +08:00
Verto.prototype.makeShare = function () {
if (this.share_call) {
2016-06-20 23:59:48 +08:00
this.logError('Quitting: Call already in progress');
2016-06-17 23:43:03 +08:00
return;
}
var screenInfo = null;
if (!!navigator.mozGetUserMedia) {
return this.onFail();
/*screenInfo = {
2016-06-20 23:59:48 +08:00
mozMediaSource: 'window',
mediaSource: 'window',
2016-06-17 23:43:03 +08:00
};
this.doShare(screenInfo);*/
2016-06-17 23:43:03 +08:00
} else if (!!window.chrome) {
var _this = this;
2016-06-18 04:36:45 +08:00
if (!_this.chromeExtension) {
_this.logError({
2016-06-20 23:59:48 +08:00
status: 'failed',
message: 'Missing Chrome Extension key',
2016-06-17 23:43:03 +08:00
});
2016-06-18 04:36:45 +08:00
_this.onFail();
return;
2016-06-17 23:43:03 +08:00
}
2016-10-05 22:35:35 +08:00
// bring up Chrome screen picker
getMyScreenConstraints(function (constraints) {
if (constraints == null || constraints == "" || constraints.streamId == null || constraints.streamId == "") {
2016-06-18 04:36:45 +08:00
_this.onFail();
2016-10-05 22:35:35 +08:00
return _this.logError(constraints);
2016-06-17 23:43:03 +08:00
}
2017-02-22 05:07:42 +08:00
screenInfo = {
chromeMediaSource: "desktop",
chromeMediaSourceId: constraints.streamId,
2017-03-29 23:58:43 +08:00
maxWidth: window.screen.width > 1920 ? window.screen.width : 1920,
maxHeight: window.screen.height > 1080 ? window.screen.height : 1080
2017-02-22 05:07:42 +08:00
};
2016-06-17 23:43:03 +08:00
2016-10-05 22:35:35 +08:00
_this.logger(screenInfo);
_this.doShare(screenInfo);
}, _this.chromeExtension);
2016-06-17 23:43:03 +08:00
}
};
2016-06-20 23:59:48 +08:00
Verto.prototype.doShare = function (screenConstraints) {
screenConstraints.maxWidth = this.vid_width;
screenConstraints.maxHeight = this.vid_height;
2016-06-20 23:05:39 +08:00
this.share_call = window.vertoHandle.newCall({
2016-06-17 23:43:03 +08:00
destination_number: this.destination_number,
caller_id_name: this.caller_id_name,
caller_id_number: this.caller_id_number,
2016-10-05 22:35:35 +08:00
outgoingBandwidth: "default",
incomingBandwidth: "default",
2017-02-22 05:07:42 +08:00
videoParams: screenConstraints,
2016-06-17 23:43:03 +08:00
useVideo: true,
screenShare: true,
2016-12-02 01:00:15 +08:00
useCamera: this.useCamera,
useMic: this.useMic,
useSpeak: 'any',
2016-06-17 23:43:03 +08:00
dedEnc: true,
mirrorInput: false,
2016-06-20 23:05:39 +08:00
tag: this.renderTag,
2016-06-17 23:43:03 +08:00
});
2016-10-06 03:57:09 +08:00
var stopSharing = function() {
console.log("stopSharing");
this.share_call.hangup();
this.share_call = null;
};
var _this = this;
// Override onStream callback in $.FSRTC instance
this.share_call.rtc.options.callbacks.onStream = function (rtc, stream) {
if (stream) {
var StreamTrack = stream.getVideoTracks()[0];
StreamTrack.addEventListener('ended', stopSharing.bind(_this));
}
};
2016-06-09 04:07:43 +08:00
};
Verto.prototype.init = function () {
this.cur_call = null;
2016-06-20 23:05:39 +08:00
if (!window.vertoHandle) {
window.vertoHandle = new $.verto({
useVideo: true,
2016-06-20 23:05:39 +08:00
login: this.login,
passwd: this.password,
socketUrl: this.socketUrl,
tag: this.renderTag,
2016-06-20 23:59:48 +08:00
ringFile: 'sounds/bell_ring2.wav',
2016-06-20 23:05:39 +08:00
sessid: this.sessid,
videoParams: {
2016-06-20 23:59:48 +08:00
minFrameRate: 15,
vertoBestFrameRate: 30,
2016-06-20 23:05:39 +08:00
},
deviceParams: {
useCamera: false,
useMic: false,
useSpeak: 'none',
},
audioParams: {
googAutoGainControl: false,
googNoiseSuppression: false,
googHighpassFilter: false,
},
iceServers: this.iceServers,
}, this.callbacks);
} else {
this.mediaCallback();
return;
}
2016-06-09 04:07:43 +08:00
};
2016-06-20 23:59:48 +08:00
Verto.prototype.configStuns = function (callback) {
this.logger('Fetching STUN/TURN server info for Verto initialization');
2016-06-09 04:07:43 +08:00
var _this = this;
var stunsConfig = {};
$.ajax({
dataType: 'json',
2016-06-20 23:59:48 +08:00
url: '/bigbluebutton/api/stuns/',
}).done(function (data) {
_this.logger('ajax request done');
2016-06-09 04:07:43 +08:00
_this.logger(data);
2016-06-20 23:59:48 +08:00
if (data.response && data.response.returncode == 'FAILED') {
_this.logError(data.response.message, { error: true });
_this.logError({ status: 'failed', errorcode: data.response.message });
2016-06-09 04:07:43 +08:00
return;
}
2016-06-20 23:59:48 +08:00
stunsConfig.stunServers = (data.stunServers ? data.stunServers.map(function (data) {
return { url: data.url };
}) : []);
stunsConfig.turnServers = (data.turnServers ? data.turnServers.map(function (data) {
2016-06-09 04:07:43 +08:00
return {
2016-06-20 23:59:48 +08:00
urls: data.url,
username: data.username,
credential: data.password,
2016-06-09 04:07:43 +08:00
};
2016-06-20 23:59:48 +08:00
}) : []);
stunsConfig = stunsConfig.stunServers.concat(stunsConfig.turnServers);
_this.logger('success got stun data, making verto');
2016-06-09 04:07:43 +08:00
_this.iceServers = stunsConfig;
callback.apply(_this);
2016-06-20 23:59:48 +08:00
}).fail(function (data, textStatus, errorThrown) {
_this.logError({ status: 'failed', errorcode: 1009 });
2016-06-18 04:36:45 +08:00
_this.onFail();
2016-06-09 04:07:43 +08:00
return;
});
};
2015-07-10 23:13:13 +08:00
// checks whether Google Chrome or Firefox have the WebRTCPeerConnection object
2016-06-09 04:07:43 +08:00
Verto.prototype.isWebRTCAvailable = function () {
2016-06-20 23:59:48 +08:00
return (typeof window.webkitRTCPeerConnection !== 'undefined' ||
typeof window.mozRTCPeerConnection !== 'undefined');
2016-06-09 04:07:43 +08:00
};
this.VertoManager = function () {
this.vertoAudio = null;
this.vertoVideo = null;
2016-06-15 00:11:04 +08:00
this.vertoScreenShare = null;
2016-06-20 23:05:39 +08:00
window.vertoHandle = null;
};
2016-06-20 23:59:48 +08:00
Verto.prototype.logout = function () {
2016-06-20 23:05:39 +08:00
this.exitAudio();
this.exitVideo();
this.exitScreenShare();
window.vertoHandle.logout();
2016-06-09 04:07:43 +08:00
};
2016-06-20 23:59:48 +08:00
VertoManager.prototype.exitAudio = function () {
2016-06-09 04:07:43 +08:00
if (this.vertoAudio != null) {
console.log('Hanging up vertoAudio');
2016-06-09 04:07:43 +08:00
this.vertoAudio.hangup();
this.vertoAudio = null;
}
};
2016-06-20 23:59:48 +08:00
VertoManager.prototype.exitVideo = function () {
2016-06-09 04:07:43 +08:00
if (this.vertoVideo != null) {
console.log('Hanging up vertoVideo');
2016-06-09 04:07:43 +08:00
this.vertoVideo.hangup();
this.vertoVideo = null;
}
};
2016-06-20 23:59:48 +08:00
VertoManager.prototype.exitScreenShare = function () {
2016-06-15 00:11:04 +08:00
if (this.vertoScreenShare != null) {
console.log('Hanging up vertoScreenShare');
2016-06-15 00:11:04 +08:00
this.vertoScreenShare.hangup();
this.vertoScreenShare = null;
}
};
2016-06-18 04:36:45 +08:00
VertoManager.prototype.joinListenOnly = function (tag) {
2016-06-09 04:07:43 +08:00
this.exitAudio();
2016-06-18 04:36:45 +08:00
var obj = Object.create(Verto.prototype);
Verto.apply(obj, arguments);
this.vertoAudio = obj;
2016-06-09 04:07:43 +08:00
this.vertoAudio.setListenOnly(tag);
};
2016-06-18 04:36:45 +08:00
VertoManager.prototype.joinMicrophone = function (tag) {
2016-06-20 23:59:48 +08:00
this.exitAudio();
var obj = Object.create(Verto.prototype);
Verto.apply(obj, arguments);
this.vertoAudio = obj;
this.vertoAudio.setMicrophone(tag);
2016-06-09 04:07:43 +08:00
};
2016-06-18 04:36:45 +08:00
VertoManager.prototype.joinWatchVideo = function (tag) {
2016-06-20 23:59:48 +08:00
this.exitVideo();
var obj = Object.create(Verto.prototype);
Verto.apply(obj, arguments);
this.vertoVideo = obj;
this.vertoVideo.setWatchVideo(tag);
2015-07-10 23:13:13 +08:00
};
2016-06-15 00:11:04 +08:00
2016-06-18 04:36:45 +08:00
VertoManager.prototype.shareScreen = function (tag) {
2016-06-20 23:59:48 +08:00
this.exitScreenShare();
var obj = Object.create(Verto.prototype);
Verto.apply(obj, arguments);
this.vertoScreenShare = obj;
this.vertoScreenShare.setScreenShare(tag);
2016-06-15 00:11:04 +08:00
};
2016-06-18 01:47:24 +08:00
2016-06-18 01:50:04 +08:00
window.vertoInitialize = function () {
if (window.vertoManager == null || window.vertoManager == undefined) {
2016-06-18 01:47:24 +08:00
window.vertoManager = new VertoManager();
}
};
2016-06-18 01:50:04 +08:00
window.vertoExitAudio = function () {
window.vertoInitialize();
window.vertoManager.exitAudio();
};
2016-09-15 04:25:31 +08:00
window.vertoExitVideo = function () {
window.vertoInitialize();
window.vertoManager.exitVideo();
};
2016-06-18 01:50:04 +08:00
window.vertoExitScreenShare = function () {
window.vertoInitialize();
window.vertoManager.exitScreenShare();
};
2016-06-18 04:36:45 +08:00
window.vertoJoinListenOnly = function () {
2016-06-18 01:50:04 +08:00
window.vertoInitialize();
2016-06-18 04:36:45 +08:00
window.vertoManager.joinListenOnly.apply(window.vertoManager, arguments);
2016-06-18 01:47:24 +08:00
};
2016-06-18 04:36:45 +08:00
window.vertoJoinMicrophone = function () {
2016-06-18 01:50:04 +08:00
window.vertoInitialize();
2016-06-18 04:36:45 +08:00
window.vertoManager.joinMicrophone.apply(window.vertoManager, arguments);
2016-06-18 01:47:24 +08:00
};
2016-06-18 04:36:45 +08:00
window.vertoWatchVideo = function () {
2016-06-18 01:50:04 +08:00
window.vertoInitialize();
2016-06-18 04:36:45 +08:00
window.vertoManager.joinWatchVideo.apply(window.vertoManager, arguments);
2016-06-18 01:47:24 +08:00
};
2016-06-18 01:50:04 +08:00
2016-06-18 04:36:45 +08:00
window.vertoShareScreen = function () {
2016-06-18 01:50:04 +08:00
window.vertoInitialize();
2016-06-18 04:36:45 +08:00
window.vertoManager.shareScreen.apply(window.vertoManager, arguments);
2016-06-18 01:50:04 +08:00
};
2016-10-05 22:35:35 +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 = Verto.normalizeCallback(isIncognito);
isNotIncognito = Verto.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 = Verto.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);
}
);
}
window.getMyScreenConstraints = function(theCallback, extensionId) {
theCallback = Verto.normalizeCallback(theCallback);
chrome.runtime.sendMessage(extensionId, {
getStream: true,
sources: [
"window",
2017-05-02 23:01:05 +08:00
"screen",
"tab"
2016-10-05 22:35:35 +08:00
]},
function(response) {
console.log(response);
theCallback(response);
});
};