Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

Removes duplication. Allows automated functional testing to access the WebRTC data channels.

Lyubomir Marinovc992222c7057
diff --git a/modules/RTC/DataChannels.js b/modules/RTC/DataChannels.js
index 0f10d71c43..9f09bf287e 100644
--- a/modules/RTC/DataChannels.js
+++ b/modules/RTC/DataChannels.js
@@ -8,7 +8,6 @@ var RTCEvents = require("../../service/RTC/RTCEvents");
var _dataChannels = [];
var eventEmitter = null;
-
var DataChannels = {
/**
* Callback triggered by PeerConnection when new data channel is opened
@@ -99,6 +98,11 @@ var DataChannels = {
}
else {
console.debug("Data channel JSON-formatted message: ", obj);
+ // The received message appears to be appropriately
+ // formatted (i.e. is a JSON object which assigns a value to
+ // the mandatory property colibriClass) so don't just
+ // swallow it, expose it to public consumption.
+ eventEmitter.emit("rtc.datachannel." + colibriClass, obj);
}
}
};
@@ -146,45 +150,61 @@ var DataChannels = {
console.info("Got My Data Channel Message:", msgData, dataChannel);
};*/
},
- handleSelectedEndpointEvent: onSelectedEndpointChanged,
- handlePinnedEndpointEvent: onPinnedEndpointChanged
-};
-function onSelectedEndpointChanged(userResource) {
- console.log('selected endpoint changed: ', userResource);
- if (_dataChannels && _dataChannels.length !== 0) {
- _dataChannels.some(function (dataChannel) {
- if (dataChannel.readyState == 'open') {
- console.log('sending selected endpoint changed ' +
- 'notification to the bridge: ', userResource);
- dataChannel.send(JSON.stringify({
- 'colibriClass': 'SelectedEndpointChangedEvent',
- 'selectedEndpoint':
- (!userResource || userResource === null)?
- null : userResource
- }));
-
- return true;
- }
- });
- }
-}
+ handleSelectedEndpointEvent: function (userResource) {
+ onXXXEndpointChanged("selected", userResource);
+ },
+ handlePinnedEndpointEvent: function (userResource) {
+ onXXXEndpointChanged("pinned", userResource);
+ },
-function onPinnedEndpointChanged(userResource) {
- console.log('pinned endpoint changed: ', userResource);
- if (_dataChannels && _dataChannels.length !== 0) {
- _dataChannels.some(function (dataChannel) {
- if (dataChannel.readyState == 'open') {
- dataChannel.send(JSON.stringify({
- 'colibriClass': 'PinnedEndpointChangedEvent',
- 'pinnedEndpoint':
- userResource ? userResource : null
- }));
-
- return true;
- }
- });
+ some: function (callback, thisArg) {
+ if (_dataChannels && _dataChannels.length !== 0) {
+ if (thisArg)
+ return _dataChannels.some(callback, thisArg);
+ else
+ return _dataChannels.some(callback);
+ } else {
+ return false;
+ }
}
+};
+
+/**
+ * Notifies Videobridge about a change in the value of a specific
+ * endpoint-related property such as selected endpoint and pinnned endpoint.
+ *
+ * @param xxx the name of the endpoint-related property whose value changed
+ * @param userResource the new value of the endpoint-related property after the
+ * change
+ */
+function onXXXEndpointChanged(xxx, userResource) {
+ // Derive the correct words from xxx such as selected and Selected, pinned
+ // and Pinned.
+ var head = xxx.charAt(0);
+ var tail = xxx.substring(1);
+ var lower = head.toLowerCase() + tail;
+ var upper = head.toUpperCase() + tail;
+
+ // Notify Videobridge about the specified endpoint change.
+ console.log(lower + ' endpoint changed: ', userResource);
+ DataChannels.some(function (dataChannel) {
+ if (dataChannel.readyState == 'open') {
+ console.log(
+ 'sending ' + lower
+ + ' endpoint changed notification to the bridge: ',
+ userResource);
+
+ var jsonObject = {};
+
+ jsonObject.colibriClass = (upper + 'EndpointChangedEvent');
+ jsonObject[lower + "Endpoint"]
+ = (userResource ? userResource : null);
+ dataChannel.send(JSON.stringify(jsonObject));
+
+ return true;
+ }
+ });
}
module.exports = DataChannels;
diff --git a/modules/RTC/RTC.js b/modules/RTC/RTC.js
index 6f8932bf1d..6a0a1107bf 100644
--- a/modules/RTC/RTC.js
+++ b/modules/RTC/RTC.js
@@ -44,6 +44,10 @@ function getMediaStreamUsage()
}
var RTC = {
+ // Exposes DataChannels to public consumption (e.g. jitsi-meet-torture)
+ // without the necessity to require the module.
+ "DataChannels": DataChannels,
+
rtcUtils: null,
devices: {
audio: true,