瀏覽代碼

Merge pull request #1253 from jitsi/api_participant_count

Iframe API - participant count
j8
Дамян Минков 8 年之前
父節點
當前提交
640c0faff1
共有 5 個檔案被更改,包括 69 行新增81 行删除
  1. 22
    0
      doc/api/api.html
  2. 5
    0
      doc/api/api.md
  3. 5
    62
      modules/API/API.js
  4. 36
    16
      modules/API/external/external_api.js
  5. 1
    3
      modules/tokendata/TokenData.js

+ 22
- 0
doc/api/api.html 查看文件

@@ -0,0 +1,22 @@
1
+<html itemscope itemtype="http://schema.org/Product" prefix="og: http://ogp.me/ns#" xmlns="http://www.w3.org/1999/html">
2
+    <head>
3
+        <meta charset="utf-8">
4
+        <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
+    </head>
6
+    <body>
7
+        <script src="https://meet.jit.si/external_api.js"></script>
8
+        <script>
9
+            var domain = "meet.jit.si";
10
+            var room = "JitsiMeetAPIExample";
11
+            var width = 700;
12
+            var height = 180;
13
+            var htmlElement = undefined;
14
+            var configOverwrite = {};
15
+            var interfaceConfigOverwrite = {
16
+                filmStripOnly: true
17
+            };
18
+            var api = new JitsiMeetExternalAPI(domain, room, width, height,
19
+                htmlElement, configOverwrite, interfaceConfigOverwrite);
20
+        </script>
21
+    </body>
22
+</html>

doc/api.md → doc/api/api.md 查看文件

@@ -202,6 +202,11 @@ If you want to remove more than one event you can use ```removeEventListeners```
202 202
 api.removeEventListeners(["incomingMessage", "outgoingMessageListener"]);
203 203
 ```
204 204
 
205
+You can get the number of participants in the conference with the following code:
206
+```
207
+var numberOfParticipants = api.getNumberOfParticipants();
208
+```
209
+
205 210
 You can remove the embedded Jitsi Meet Conference with the following code:
206 211
 ```
207 212
 api.dispose()

+ 5
- 62
modules/API/API.js 查看文件

@@ -1,5 +1,4 @@
1 1
 /* global APP, getConfigParamsFromUrl */
2
-const logger = require("jitsi-meet-logger").getLogger(__filename);
3 2
 
4 3
 /**
5 4
  * Implements API class that communicates with external api class
@@ -63,31 +62,6 @@ function initCommands() {
63 62
     });
64 63
 }
65 64
 
66
-
67
-/**
68
- * Maps the supported events and their status
69
- * (true it the event is enabled and false if it is disabled)
70
- * @type {{
71
- *              incoming-message: boolean,
72
- *              outgoing-message: boolean,
73
- *              display-name-change: boolean,
74
- *              participant-left: boolean,
75
- *              participant-joined: boolean,
76
- *              video-conference-left: boolean,
77
- *              video-conference-joined: boolean
78
- *      }}
79
- */
80
-const events = {
81
-    "incoming-message": false,
82
-    "outgoing-message":false,
83
-    "display-name-change": false,
84
-    "participant-joined": false,
85
-    "participant-left": false,
86
-    "video-conference-joined": false,
87
-    "video-conference-left": false,
88
-    "video-ready-to-close": false
89
-};
90
-
91 65
 /**
92 66
  * Sends message to the external application.
93 67
  * @param message {object}
@@ -95,27 +69,19 @@ const events = {
95 69
  * @param params {object} the object that will be sent as JSON string
96 70
  */
97 71
 function sendMessage(message) {
98
-    if(enabled)
72
+    if(enabled) {
99 73
         postis.send(message);
74
+    }
100 75
 }
101 76
 
102 77
 /**
103 78
  * Check whether the API should be enabled or not.
104 79
  * @returns {boolean}
105 80
  */
106
-function isEnabled () {
81
+function shouldBeEnabled () {
107 82
     return (typeof jitsi_meet_external_api_id === "number");
108 83
 }
109 84
 
110
-/**
111
- * Checks whether the event is enabled ot not.
112
- * @param name the name of the event.
113
- * @returns {*}
114
- */
115
-function isEventEnabled (name) {
116
-    return events[name];
117
-}
118
-
119 85
 /**
120 86
  * Sends event object to the external application that has been subscribed
121 87
  * for that event.
@@ -123,25 +89,8 @@ function isEventEnabled (name) {
123 89
  * @param object data associated with the event
124 90
  */
125 91
 function triggerEvent (name, object) {
126
-    if(isEventEnabled(name))
92
+    if(enabled) {
127 93
         sendMessage({method: name, params: object});
128
-}
129
-
130
-/**
131
- * Handles system messages. (for example: enable/disable events)
132
- * @param message {object} the message
133
- */
134
-function onSystemMessage(message) {
135
-    switch (message.type) {
136
-        case "eventStatus":
137
-            if(!message.name || !message.value) {
138
-                logger.warn("Unknown system message format", message);
139
-                break;
140
-            }
141
-            events[message.name] = message.value;
142
-            break;
143
-        default:
144
-            logger.warn("Unknown system message type", message);
145 94
     }
146 95
 }
147 96
 
@@ -153,17 +102,12 @@ export default {
153 102
      * is initialized.
154 103
      * @param options {object}
155 104
      * @param forceEnable {boolean} if true the module will be enabled.
156
-     * @param enabledEvents {array} array of events that should be enabled.
157 105
      */
158 106
     init (options = {}) {
159
-        if(!isEnabled() && !options.forceEnable)
107
+        if(!shouldBeEnabled() && !options.forceEnable)
160 108
             return;
161 109
 
162 110
         enabled = true;
163
-        if(options.enabledEvents)
164
-            options.enabledEvents.forEach(function (eventName) {
165
-                events[eventName] = true;
166
-            });
167 111
         let postisOptions = {
168 112
             window: target
169 113
         };
@@ -171,7 +115,6 @@ export default {
171 115
             postisOptions.scope
172 116
                 = "jitsi_meet_external_api_" + jitsi_meet_external_api_id;
173 117
         postis = postisInit(postisOptions);
174
-        postis.listen("jitsiSystemMessage", onSystemMessage);
175 118
         initCommands();
176 119
     },
177 120
 

+ 36
- 16
modules/API/external/external_api.js 查看文件

@@ -69,20 +69,15 @@ function sendMessage(postis, object) {
69 69
 }
70 70
 
71 71
 /**
72
- * Sends message for event enable/disable status change.
73
- * @param postis {Postis object} the postis instance that is going to be used.
74
- * @param event {string} the name of the event
75
- * @param status {boolean} true - enabled; false - disabled;
72
+ * Adds given number to the numberOfParticipants property of given APIInstance.
73
+ * @param {JitsiMeetExternalAPI} APIInstance the instance of the
74
+ * JitsiMeetExternalAPI
75
+ * @param {int} number - the number of participants to be added to
76
+ * numberOfParticipants property (this parameter can be negative number if the
77
+ * numberOfParticipants should be decreased).
76 78
  */
77
-function changeEventStatus(postis, event, status) {
78
-    if(!(event in events)) {
79
-        logger.error("Not supported event name.");
80
-        return;
81
-    }
82
-    sendMessage(postis, {
83
-        method: "jitsiSystemMessage",
84
-        params: {type: "eventStatus", name: events[event], value: status}
85
-    });
79
+function changeParticipantNumber(APIInstance, number) {
80
+    APIInstance.numberOfParticipants += number;
86 81
 }
87 82
 
88 83
 /**
@@ -161,6 +156,12 @@ function JitsiMeetExternalAPI(domain, room_name, width, height, parentNode,
161 156
 
162 157
     this.eventHandlers = {};
163 158
 
159
+    // Map<{string} event_name, {boolean} postis_listener_added>
160
+    this.postisListeners = {};
161
+
162
+    this.numberOfParticipants = 1;
163
+    this._setupListeners();
164
+
164 165
     id++;
165 166
 }
166 167
 
@@ -313,14 +314,15 @@ JitsiMeetExternalAPI.prototype.addEventListener = function(event, listener) {
313 314
     }
314 315
     // We cannot remove listeners from postis that's why we are handling the
315 316
     // callback that way.
316
-    if(!(event in this.eventHandlers))
317
+    if(!this.postisListeners[event]) {
317 318
         this.postis.listen(events[event], function(data) {
318 319
             if((event in this.eventHandlers) &&
319 320
                 typeof this.eventHandlers[event] === "function")
320 321
                 this.eventHandlers[event].call(null, data);
321 322
         }.bind(this));
323
+        this.postisListeners[event] = true;
324
+    }
322 325
     this.eventHandlers[event] = listener;
323
-    changeEventStatus(this.postis, event, true);
324 326
 };
325 327
 
326 328
 /**
@@ -334,7 +336,6 @@ JitsiMeetExternalAPI.prototype.removeEventListener = function(event) {
334 336
         return;
335 337
     }
336 338
     delete this.eventHandlers[event];
337
-    changeEventStatus(this.postis, event, false);
338 339
 };
339 340
 
340 341
 /**
@@ -346,6 +347,25 @@ JitsiMeetExternalAPI.prototype.removeEventListeners = function(events) {
346 347
         this.removeEventListener(events[i]);
347 348
 };
348 349
 
350
+/**
351
+ * Returns the number of participants in the conference.
352
+ * NOTE: the local participant is included.
353
+ * @returns {int} the number of participants in the conference.
354
+ */
355
+JitsiMeetExternalAPI.prototype.getNumberOfParticipants = function() {
356
+    return this.numberOfParticipants;
357
+};
358
+
359
+/**
360
+ * Setups listeners that are used internally for JitsiMeetExternalAPI.
361
+ */
362
+JitsiMeetExternalAPI.prototype._setupListeners = function() {
363
+    this.postis.listen("participant-joined",
364
+        changeParticipantNumber.bind(null, this, 1));
365
+    this.postis.listen("participant-left",
366
+        changeParticipantNumber.bind(null, this, -1));
367
+};
368
+
349 369
 /**
350 370
  * Removes the listeners and removes the Jitsi Meet frame.
351 371
  */

+ 1
- 3
modules/tokendata/TokenData.js 查看文件

@@ -75,9 +75,7 @@ class TokenData{
75 75
 
76 76
         //External API settings
77 77
         this.externalAPISettings = {
78
-            forceEnable: true,
79
-            enabledEvents: ["video-conference-joined", "video-conference-left",
80
-                "video-ready-to-close"]
78
+            forceEnable: true
81 79
         };
82 80
         this._decode();
83 81
         // Use JWT param as token if there is not other token set and if the

Loading…
取消
儲存