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

This commit is contained in:
Lyubomir Marinov 2015-09-22 18:51:24 -05:00
parent 506d0722bd
commit c992222c70
2 changed files with 59 additions and 35 deletions

View File

@ -8,7 +8,6 @@ var RTCEvents = require("../../service/RTC/RTCEvents");
var _dataChannels = []; var _dataChannels = [];
var eventEmitter = null; var eventEmitter = null;
var DataChannels = { var DataChannels = {
/** /**
* Callback triggered by PeerConnection when new data channel is opened * Callback triggered by PeerConnection when new data channel is opened
@ -99,6 +98,11 @@ var DataChannels = {
} }
else { else {
console.debug("Data channel JSON-formatted message: ", obj); 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); console.info("Got My Data Channel Message:", msgData, dataChannel);
};*/ };*/
}, },
handleSelectedEndpointEvent: onSelectedEndpointChanged,
handlePinnedEndpointEvent: onPinnedEndpointChanged handleSelectedEndpointEvent: function (userResource) {
onXXXEndpointChanged("selected", userResource);
},
handlePinnedEndpointEvent: function (userResource) {
onXXXEndpointChanged("pinned", userResource);
},
some: function (callback, thisArg) {
if (_dataChannels && _dataChannels.length !== 0) {
if (thisArg)
return _dataChannels.some(callback, thisArg);
else
return _dataChannels.some(callback);
} else {
return false;
}
}
}; };
function onSelectedEndpointChanged(userResource) { /**
console.log('selected endpoint changed: ', userResource); * Notifies Videobridge about a change in the value of a specific
if (_dataChannels && _dataChannels.length !== 0) { * endpoint-related property such as selected endpoint and pinnned endpoint.
_dataChannels.some(function (dataChannel) { *
if (dataChannel.readyState == 'open') { * @param xxx the name of the endpoint-related property whose value changed
console.log('sending selected endpoint changed ' + * @param userResource the new value of the endpoint-related property after the
'notification to the bridge: ', userResource); * change
dataChannel.send(JSON.stringify({ */
'colibriClass': 'SelectedEndpointChangedEvent', function onXXXEndpointChanged(xxx, userResource) {
'selectedEndpoint': // Derive the correct words from xxx such as selected and Selected, pinned
(!userResource || userResource === null)? // and Pinned.
null : userResource var head = xxx.charAt(0);
})); var tail = xxx.substring(1);
var lower = head.toLowerCase() + tail;
var upper = head.toUpperCase() + tail;
return true; // 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);
function onPinnedEndpointChanged(userResource) { var jsonObject = {};
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; jsonObject.colibriClass = (upper + 'EndpointChangedEvent');
} jsonObject[lower + "Endpoint"]
}); = (userResource ? userResource : null);
} dataChannel.send(JSON.stringify(jsonObject));
return true;
}
});
} }
module.exports = DataChannels; module.exports = DataChannels;

View File

@ -44,6 +44,10 @@ function getMediaStreamUsage()
} }
var RTC = { var RTC = {
// Exposes DataChannels to public consumption (e.g. jitsi-meet-torture)
// without the necessity to require the module.
"DataChannels": DataChannels,
rtcUtils: null, rtcUtils: null,
devices: { devices: {
audio: true, audio: true,