Merge pull request #1253 from jitsi/api_participant_count
Iframe API - participant count
This commit is contained in:
commit
640c0faff1
|
@ -0,0 +1,22 @@
|
|||
<html itemscope itemtype="http://schema.org/Product" prefix="og: http://ogp.me/ns#" xmlns="http://www.w3.org/1999/html">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="content-type" content="text/html;charset=utf-8">
|
||||
</head>
|
||||
<body>
|
||||
<script src="https://meet.jit.si/external_api.js"></script>
|
||||
<script>
|
||||
var domain = "meet.jit.si";
|
||||
var room = "JitsiMeetAPIExample";
|
||||
var width = 700;
|
||||
var height = 180;
|
||||
var htmlElement = undefined;
|
||||
var configOverwrite = {};
|
||||
var interfaceConfigOverwrite = {
|
||||
filmStripOnly: true
|
||||
};
|
||||
var api = new JitsiMeetExternalAPI(domain, room, width, height,
|
||||
htmlElement, configOverwrite, interfaceConfigOverwrite);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -202,6 +202,11 @@ If you want to remove more than one event you can use ```removeEventListeners```
|
|||
api.removeEventListeners(["incomingMessage", "outgoingMessageListener"]);
|
||||
```
|
||||
|
||||
You can get the number of participants in the conference with the following code:
|
||||
```
|
||||
var numberOfParticipants = api.getNumberOfParticipants();
|
||||
```
|
||||
|
||||
You can remove the embedded Jitsi Meet Conference with the following code:
|
||||
```
|
||||
api.dispose()
|
|
@ -1,5 +1,4 @@
|
|||
/* global APP, getConfigParamsFromUrl */
|
||||
const logger = require("jitsi-meet-logger").getLogger(__filename);
|
||||
|
||||
/**
|
||||
* Implements API class that communicates with external api class
|
||||
|
@ -63,31 +62,6 @@ function initCommands() {
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Maps the supported events and their status
|
||||
* (true it the event is enabled and false if it is disabled)
|
||||
* @type {{
|
||||
* incoming-message: boolean,
|
||||
* outgoing-message: boolean,
|
||||
* display-name-change: boolean,
|
||||
* participant-left: boolean,
|
||||
* participant-joined: boolean,
|
||||
* video-conference-left: boolean,
|
||||
* video-conference-joined: boolean
|
||||
* }}
|
||||
*/
|
||||
const events = {
|
||||
"incoming-message": false,
|
||||
"outgoing-message":false,
|
||||
"display-name-change": false,
|
||||
"participant-joined": false,
|
||||
"participant-left": false,
|
||||
"video-conference-joined": false,
|
||||
"video-conference-left": false,
|
||||
"video-ready-to-close": false
|
||||
};
|
||||
|
||||
/**
|
||||
* Sends message to the external application.
|
||||
* @param message {object}
|
||||
|
@ -95,27 +69,19 @@ const events = {
|
|||
* @param params {object} the object that will be sent as JSON string
|
||||
*/
|
||||
function sendMessage(message) {
|
||||
if(enabled)
|
||||
if(enabled) {
|
||||
postis.send(message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the API should be enabled or not.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isEnabled () {
|
||||
function shouldBeEnabled () {
|
||||
return (typeof jitsi_meet_external_api_id === "number");
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the event is enabled ot not.
|
||||
* @param name the name of the event.
|
||||
* @returns {*}
|
||||
*/
|
||||
function isEventEnabled (name) {
|
||||
return events[name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends event object to the external application that has been subscribed
|
||||
* for that event.
|
||||
|
@ -123,25 +89,8 @@ function isEventEnabled (name) {
|
|||
* @param object data associated with the event
|
||||
*/
|
||||
function triggerEvent (name, object) {
|
||||
if(isEventEnabled(name))
|
||||
if(enabled) {
|
||||
sendMessage({method: name, params: object});
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles system messages. (for example: enable/disable events)
|
||||
* @param message {object} the message
|
||||
*/
|
||||
function onSystemMessage(message) {
|
||||
switch (message.type) {
|
||||
case "eventStatus":
|
||||
if(!message.name || !message.value) {
|
||||
logger.warn("Unknown system message format", message);
|
||||
break;
|
||||
}
|
||||
events[message.name] = message.value;
|
||||
break;
|
||||
default:
|
||||
logger.warn("Unknown system message type", message);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -153,17 +102,12 @@ export default {
|
|||
* is initialized.
|
||||
* @param options {object}
|
||||
* @param forceEnable {boolean} if true the module will be enabled.
|
||||
* @param enabledEvents {array} array of events that should be enabled.
|
||||
*/
|
||||
init (options = {}) {
|
||||
if(!isEnabled() && !options.forceEnable)
|
||||
if(!shouldBeEnabled() && !options.forceEnable)
|
||||
return;
|
||||
|
||||
enabled = true;
|
||||
if(options.enabledEvents)
|
||||
options.enabledEvents.forEach(function (eventName) {
|
||||
events[eventName] = true;
|
||||
});
|
||||
let postisOptions = {
|
||||
window: target
|
||||
};
|
||||
|
@ -171,7 +115,6 @@ export default {
|
|||
postisOptions.scope
|
||||
= "jitsi_meet_external_api_" + jitsi_meet_external_api_id;
|
||||
postis = postisInit(postisOptions);
|
||||
postis.listen("jitsiSystemMessage", onSystemMessage);
|
||||
initCommands();
|
||||
},
|
||||
|
||||
|
|
|
@ -69,20 +69,15 @@ function sendMessage(postis, object) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Sends message for event enable/disable status change.
|
||||
* @param postis {Postis object} the postis instance that is going to be used.
|
||||
* @param event {string} the name of the event
|
||||
* @param status {boolean} true - enabled; false - disabled;
|
||||
* Adds given number to the numberOfParticipants property of given APIInstance.
|
||||
* @param {JitsiMeetExternalAPI} APIInstance the instance of the
|
||||
* JitsiMeetExternalAPI
|
||||
* @param {int} number - the number of participants to be added to
|
||||
* numberOfParticipants property (this parameter can be negative number if the
|
||||
* numberOfParticipants should be decreased).
|
||||
*/
|
||||
function changeEventStatus(postis, event, status) {
|
||||
if(!(event in events)) {
|
||||
logger.error("Not supported event name.");
|
||||
return;
|
||||
}
|
||||
sendMessage(postis, {
|
||||
method: "jitsiSystemMessage",
|
||||
params: {type: "eventStatus", name: events[event], value: status}
|
||||
});
|
||||
function changeParticipantNumber(APIInstance, number) {
|
||||
APIInstance.numberOfParticipants += number;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -161,6 +156,12 @@ function JitsiMeetExternalAPI(domain, room_name, width, height, parentNode,
|
|||
|
||||
this.eventHandlers = {};
|
||||
|
||||
// Map<{string} event_name, {boolean} postis_listener_added>
|
||||
this.postisListeners = {};
|
||||
|
||||
this.numberOfParticipants = 1;
|
||||
this._setupListeners();
|
||||
|
||||
id++;
|
||||
}
|
||||
|
||||
|
@ -313,14 +314,15 @@ JitsiMeetExternalAPI.prototype.addEventListener = function(event, listener) {
|
|||
}
|
||||
// We cannot remove listeners from postis that's why we are handling the
|
||||
// callback that way.
|
||||
if(!(event in this.eventHandlers))
|
||||
if(!this.postisListeners[event]) {
|
||||
this.postis.listen(events[event], function(data) {
|
||||
if((event in this.eventHandlers) &&
|
||||
typeof this.eventHandlers[event] === "function")
|
||||
this.eventHandlers[event].call(null, data);
|
||||
}.bind(this));
|
||||
this.postisListeners[event] = true;
|
||||
}
|
||||
this.eventHandlers[event] = listener;
|
||||
changeEventStatus(this.postis, event, true);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -334,7 +336,6 @@ JitsiMeetExternalAPI.prototype.removeEventListener = function(event) {
|
|||
return;
|
||||
}
|
||||
delete this.eventHandlers[event];
|
||||
changeEventStatus(this.postis, event, false);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -346,6 +347,25 @@ JitsiMeetExternalAPI.prototype.removeEventListeners = function(events) {
|
|||
this.removeEventListener(events[i]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the number of participants in the conference.
|
||||
* NOTE: the local participant is included.
|
||||
* @returns {int} the number of participants in the conference.
|
||||
*/
|
||||
JitsiMeetExternalAPI.prototype.getNumberOfParticipants = function() {
|
||||
return this.numberOfParticipants;
|
||||
};
|
||||
|
||||
/**
|
||||
* Setups listeners that are used internally for JitsiMeetExternalAPI.
|
||||
*/
|
||||
JitsiMeetExternalAPI.prototype._setupListeners = function() {
|
||||
this.postis.listen("participant-joined",
|
||||
changeParticipantNumber.bind(null, this, 1));
|
||||
this.postis.listen("participant-left",
|
||||
changeParticipantNumber.bind(null, this, -1));
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes the listeners and removes the Jitsi Meet frame.
|
||||
*/
|
||||
|
|
|
@ -75,9 +75,7 @@ class TokenData{
|
|||
|
||||
//External API settings
|
||||
this.externalAPISettings = {
|
||||
forceEnable: true,
|
||||
enabledEvents: ["video-conference-joined", "video-conference-left",
|
||||
"video-ready-to-close"]
|
||||
forceEnable: true
|
||||
};
|
||||
this._decode();
|
||||
// Use JWT param as token if there is not other token set and if the
|
||||
|
|
Loading…
Reference in New Issue