Commit 14adace8 authored by Moritz Langenstein's avatar Moritz Langenstein
Browse files

(ml5717) Pre-built liowebrtc to dist/

parent 86b4b51b
node_modules
.DS_Store
dist
yarn-error.log
.eslintcache
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Edge = function () {
function Edge(startNode, endNode) {
var weight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
_classCallCheck(this, Edge);
this.node1 = startNode;
this.node2 = endNode;
this.weight = weight;
}
_createClass(Edge, [{
key: "getId",
value: function getId() {
var startNodeId = this.node1.getId();
var endNodeId = this.node2.getId();
return startNodeId + "_" + endNodeId;
}
}, {
key: "getWeight",
value: function getWeight() {
return this.weight;
}
}, {
key: "setWeight",
value: function setWeight(weight) {
this.weight = weight;
}
}, {
key: "reverse",
value: function reverse() {
var tmp = this.node1;
this.node1 = this.node2;
this.node2 = tmp;
}
}, {
key: "toString",
value: function toString() {
return this.getId();
}
}]);
return Edge;
}();
exports.default = Edge;
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var PeerGraph = function () {
function PeerGraph() {
_classCallCheck(this, PeerGraph);
this.nodes = {};
this.edges = {};
this.edgeCount = 0;
}
_createClass(PeerGraph, [{
key: "addEdge",
value: function addEdge(edge) {
var node1 = this.getNodeById(edge.node1.getId());
var node2 = this.getNodeById(edge.node2.getId());
if (!node1) {
this.addNode(edge.node1);
node1 = this.getNodeById(edge.node1.getId());
}
if (!node2) {
this.addNode(edge.node2);
node2 = this.getNodeById(edge.node2.getId());
}
if (this.edges[edge.getId()]) {
// throw new Error('Edge already exists');
} else {
this.edges[edge.getId()] = edge;
}
// Add edge to both node instances because it's an undirected graph
node1.addEdge(edge);
node2.addEdge(edge);
return this;
}
}, {
key: "addNode",
value: function addNode(newNode) {
this.nodes[newNode.getId()] = newNode;
return this;
}
}, {
key: "getNodeById",
value: function getNodeById(id) {
return this.nodes[id];
}
}, {
key: "getNeighbors",
value: function getNeighbors(node) {
return node.getNeighbors();
}
}, {
key: "getWeight",
value: function getWeight() {
return this.getAllEdges().reduce(function (weight, edge) {
return weight + edge.weight;
}, 0);
}
}, {
key: "getAllNodes",
value: function getAllNodes() {
return Object.values(this.nodes);
}
}, {
key: "getAllEdges",
value: function getAllEdges() {
return Object.values(this.edges);
}
}, {
key: "findNodeById",
value: function findNodeById(nodeId) {
if (this.nodes[nodeId]) {
return this.nodes[nodeId];
}
return null;
}
}, {
key: "findEdge",
value: function findEdge(node1, node2) {
var node = this.getNodeById(node1.getId());
if (!node) {
return null;
}
return node.findEdge(node2);
}
}, {
key: "deleteEdge",
value: function deleteEdge(edge) {
if (!edge) {
return;
}
if (this.edges[edge.getId()]) {
delete this.edges[edge.getId()];
}
var node1 = this.getNodeById(edge.node1.getId());
var node2 = this.getNodeById(edge.node2.getId());
node1.deleteEdge(edge);
node2.deleteEdge(edge);
}
}, {
key: "getNodeIndices",
value: function getNodeIndices() {
var nodeIndices = {};
this.getAllNodes().forEach(function (node, index) {
nodeIndices[node.getId()] = index;
});
return nodeIndices;
}
}, {
key: "toString",
value: function toString() {
return Object.keys(this.nodes).toString();
}
}, {
key: "toJSON",
value: function toJSON() {}
}]);
return PeerGraph;
}();
exports.default = PeerGraph;
\ No newline at end of file
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Node = function () {
function Node(value) {
_classCallCheck(this, Node);
if (value === undefined) {
throw new Error('Node must have an ID');
}
this.value = value;
this.edges = {};
}
_createClass(Node, [{
key: 'addEdge',
value: function addEdge(edge) {
this.edges[edge.getId()] = edge;
return this;
}
}, {
key: 'deleteEdge',
value: function deleteEdge(edge) {
delete this.edges[edge.getId()];
}
}, {
key: 'getEdges',
value: function getEdges() {
return Object.values(this.edges);
}
}, {
key: 'getDegree',
value: function getDegree() {
return Object.keys(this.edges).length;
}
}, {
key: 'getNeighbors',
value: function getNeighbors() {
var _this = this;
var edges = Object.values(this.edges);
var nodes = edges.map(function (e) {
return e.node1 === _this ? e.node2 : e.node1;
});
return nodes;
}
}, {
key: 'hasEdge',
value: function hasEdge(requiredEdge) {
var edgeNode = this.edges.filter(function (edge) {
return edge.getId() === requiredEdge.getId();
});
return !!edgeNode.length;
}
}, {
key: 'hasNeighbor',
value: function hasNeighbor(node) {
var nodeWeWant = Object.values(this.edges).filter(function (e) {
return e.node1.getId() === node.getId() || e.node2.getId() === node.getId();
});
return !!nodeWeWant.length;
}
}, {
key: 'findEdge',
value: function findEdge(node) {
var result = Object.values(this.edges).filter(function (e) {
return e.node1.getId() === node.getId() || e.node2.getId() === node.getId();
});
return result.length ? result[0] : null;
}
}, {
key: 'getId',
value: function getId() {
return this.value;
}
}, {
key: 'deleteAllEdges',
value: function deleteAllEdges() {
var _this2 = this;
this.getEdges().forEach(function (e) {
return _this2.deleteEdge(e);
});
return this;
}
}, {
key: 'toString',
value: function toString() {
return '' + this.value;
}
}]);
return Node;
}();
exports.default = Node;
\ No newline at end of file
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Graph = undefined;
exports.addNode = addNode;
exports.addConnection = addConnection;
exports.removeConnection = removeConnection;
exports.getNeighbors = getNeighbors;
exports.isNeighbor = isNeighbor;
exports.getPeerLatencies = getPeerLatencies;
exports.average = average;
exports.squaredDiffs = squaredDiffs;
exports.stdDeviation = stdDeviation;
exports.getLatencyZScores = getLatencyZScores;
exports.getDroppablePeer = getDroppablePeer;
var _PeerGraph = require('./PeerGraph');
var _PeerGraph2 = _interopRequireDefault(_PeerGraph);
var _Edge = require('./Edge');
var _Edge2 = _interopRequireDefault(_Edge);
var _PeerNode = require('./PeerNode');
var _PeerNode2 = _interopRequireDefault(_PeerNode);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var Graph = exports.Graph = new _PeerGraph2.default();
function addNode(nodeId) {
var node = new _PeerNode2.default(nodeId);
Graph.addNode(node);
}
function addConnection(node1Id, node2Id) {
var latency = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
var nodeA = Graph.getNodeById(node1Id) || new _PeerNode2.default(node1Id);
var nodeB = Graph.getNodeById(node2Id) || new _PeerNode2.default(node2Id);
var edgeAB = new _Edge2.default(nodeA, nodeB, latency);
return Graph.addEdge(edgeAB);
}
function removeConnection(node1Id, node2Id) {
var nodeA = Graph.getNodeById(node1Id);
var nodeB = Graph.getNodeById(node2Id);
if (nodeA && nodeB) Graph.deleteEdge(Graph.findEdge(nodeA, nodeB));
}
function getNeighbors(nodeId) {
var node = Graph.getNodeById(nodeId);
var neighbors = node.getNeighbors();
return neighbors.map(function (n) {
return n.getId();
});
}
function isNeighbor(node1Id, node2Id) {
var nodeA = Graph.getNodeById(node1Id) || new _PeerNode2.default(node1Id);
var nodeB = Graph.getNodeById(node2Id) || new _PeerNode2.default(node2Id);
if (nodeA.hasNeighbor(nodeB)) {
return true;
}
return false;
}
function getPeerLatencies(nodeId) {
var node = Graph.findNodeById(nodeId);
if (node) {
var result = {};
var edges = node.getEdges();
edges.forEach(function (e) {
var id = e.node1.getId() === nodeId ? e.node2.getId() : e.node1.getId();
var latency = e.getWeight();
result[id] = latency;
});
return result;
}
}
function average(vals) {
var total = vals.reduce(function (sum, val) {
return val + sum;
});
return total / vals.length;
}
function squaredDiffs(vals, avg) {
var sqd = vals.map(function (val) {
return Math.pow(val - avg, 2);
});
return sqd;
}
function stdDeviation(sqDiffs) {
var sum = sqDiffs.reduce(function (total, x) {
return total + x;
});
return Math.sqrt(sum / sqDiffs.length);
}
function getLatencyZScores(nodeId) {
var peerLatencyCache = getPeerLatencies(nodeId);
var peerIds = Object.keys(peerLatencyCache);
var peerLatencies = Object.values(peerLatencyCache);
var avg = average(peerLatencies);
var standardDeviation = stdDeviation(squaredDiffs(peerLatencies, avg));
var zScores = {};
peerIds.forEach(function (val, i) {
zScores[val] = (peerLatencies[i] - avg) / standardDeviation;
});
return zScores;
}
function getDroppablePeer(nodeId) {
var zScores = getLatencyZScores(nodeId);
var droppable = zScores.filter(function (s) {
return s <= -1;
});
var orderedDroppable = droppable.sort(function (a, b) {
return b - a;
});
return orderedDroppable[0];
}
\ No newline at end of file
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var inheritedMethods = exports.inheritedMethods = ['mute', 'unmute', 'pauseVideo', 'resumeVideo', 'pause', 'resume', 'sendToAll', 'sendDirectlyToAll', 'getPeers', 'getPeerByNick', 'getPeerById', 'shout', 'whisper', 'broadcast', 'transmit'];
var defaultConfig = exports.defaultConfig = {
url: 'https://sm1.lio.app:443/',
socketio: { forceNew: true },
connection: null,
debug: false,
localVideoEl: '',
remoteVideosEl: '',
enableDataChannels: true,
autoRequestMedia: false,
dataOnly: false,
autoRemoveVideos: true,
adjustPeerVolume: true,
peerVolumeWhenSpeaking: 0.25,
media: {
video: true,
audio: true
},
receiveMedia: {
offerToReceiveAudio: 1,
offerToReceiveVideo: 1
},
localVideo: {
autoplay: true,
mirror: true,
muted: true,
audio: false
},
constraints: {
maxPeers: 0,
minPeers: 2
},
selfOptimize: true
};
var defaultChannel = exports.defaultChannel = 'liowebrtc';
\ No newline at end of file
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _wildemitter = require('wildemitter');
var _wildemitter2 = _interopRequireDefault(_wildemitter);
var _attachmediastream = require('attachmediastream');
var _attachmediastream2 = _interopRequireDefault(_attachmediastream);
var _mockconsole = require('mockconsole');
var _mockconsole2 = _interopRequireDefault(_mockconsole);
var _webrtc = require('./webrtc');
var _webrtc2 = _interopRequireDefault(_webrtc);
var _webrtcsupport = require('./webrtcsupport');
var _webrtcsupport2 = _interopRequireDefault(_webrtcsupport);
var _socketioconnection = require('./socketioconnection');
var _socketioconnection2 = _interopRequireDefault(_socketioconnection);
var _PeerOptimizer = require('./PeerOptimizer');
var _constants = require('./constants');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var LioWebRTC = function (_WildEmitter) {
_inherits(LioWebRTC, _WildEmitter);
function LioWebRTC(opts) {
_classCallCheck(this, LioWebRTC);
var _this = _possibleConstructorReturn(this, (LioWebRTC.__proto__ || Object.getPrototypeOf(LioWebRTC)).call(this));
var self = _this;
var options = opts || {};
_this.config = _constants.defaultConfig;
var config = _this.config;
_this.peerDataCache = {};
_this.unconnectivePeers = {};
_this.id = '';
_this.roomCount = 0;
_this.roomName = '';
var connection = void 0;
// Set up logger
_this.logger = function () {
if (opts.debug) {
return opts.logger || console;
}
return opts.logger || _mockconsole2.default;
}();
// Set our config from options
Object.keys(options).forEach(function (o) {
_this.config[o] = options[o];
});
if (options.dataOnly) {
_this.config.media.video = false;
_this.config.media.audio = false;
_this.config.receiveMedia.offerToReceiveAudio = false;
_this.config.receiveMedia.offerToReceiveVideo = false;
}
if (!_this.config.media.video && _this.config.media.audio) {
_this.config.localVideo.audio = true;
}
_this.capabilities = _webrtcsupport2.default;
if (_this.config.connection === null) {
connection = _this.connection = new _socketioconnection2.default(_this.config);
} else {
connection = _this.connection = _this.config.connection;
}
connection.on('connect', function () {
self.emit('connectionReady', connection.getSessionid());
self.sessionReady = true;
self.testReadiness();
});
connection.on('message', function (message) {
var peers = self.webrtc.getPeers(message.from, message.roomType);
var totalPeers = self.webrtc.getPeers().length;
var peer = void 0;
if (message.type === 'offer') {
if (peers.length) {
peers.forEach(function (p) {
if (p.sid === message.sid) peer = p;
});
// if (!peer) peer = peers[0]; // fallback for old protocol versions
}
if (_this.config.dataOnly && _this.config.constraints.maxPeers > 0 && totalPeers >= _this.config.constraints.maxPeers) {
return;
}
if (!peer) {
peer = self.webrtc.createPeer({
id: message.from,
sid: message.sid,
type: message.roomType,
enableDataChannels: self.config.enableDataChannels,
sharemyscreen: message.roomType === 'screen' && !message.broadcaster,
broadcaster: message