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

(ml5717) Pre-built liowebrtc to dist/

parent 86b4b51b
node_modules node_modules
.DS_Store .DS_Store
dist
yarn-error.log yarn-error.log
.eslintcache .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
This diff is collapsed.
'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 _hark = require('hark');
var _hark2 = _interopRequireDefault(_hark);
var _wildemitter = require('wildemitter');
var _wildemitter2 = _interopRequireDefault(_wildemitter);
var _mockconsole = require('mockconsole');
var _mockconsole2 = _interopRequireDefault(_mockconsole);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: 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; }
function isAllTracksEnded(stream) {
var isAllTracksEnded = true;
stream.getTracks().forEach(function (t) {
isAllTracksEnded = t.readyState === 'ended' && isAllTracksEnded;
});
return isAllTracksEnded;
}
function shouldWorkAroundFirefoxStopStream() {
if (typeof window === 'undefined') {
return false;
}
if (!window.navigator.mozGetUserMedia) {
return false;
}
var match = window.navigator.userAgent.match(/Firefox\/(\d+)\./);
var version = match && match.length >= 1 && parseInt(match[1], 10);
return version < 50;
}
var LocalMedia = function (_WildEmitter) {
_inherits(LocalMedia, _WildEmitter);
function LocalMedia(opts) {
_classCallCheck(this, LocalMedia);
var _this = _possibleConstructorReturn(this, (LocalMedia.__proto__ || Object.getPrototypeOf(LocalMedia)).call(this));
var config = _this.config = {
detectSpeakingEvents: false,
audioFallback: false,
media: {
audio: true,
video: true
},
harkOptions: null,
logger: _mockconsole2.default
};
var item = void 0;
for (item in opts) {
if (opts.hasOwnProperty(item)) {
_this.config[item] = opts[item];
}
}
_this.logger = config.logger;
_this._log = _this.logger.log.bind(_this.logger, 'LocalMedia:');
_this._logerror = _this.logger.error.bind(_this.logger, 'LocalMedia:');
_this.localStreams = [];
_this.localScreens = [];
if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
_this._logerror('Your browser does not support local media capture.');
}
_this._audioMonitors = [];
_this.on('localStreamStopped', _this._stopAudioMonitor.bind(_this));
_this.on('localScreenStopped', _this._stopAudioMonitor.bind(_this));
return _this;
}
_createClass(LocalMedia, [{
key: 'start',
value: function start(mediaConstraints, cb) {
var self = this;
var constraints = mediaConstraints || this.config.media;
this.emit('localStreamRequested', constraints);
navigator.mediaDevices.getUserMedia(constraints).then(function (stream) {
if (constraints.audio && self.config.detectSpeakingEvents) {
self._setupAudioMonitor(stream, self.config.harkOptions);
}
self.localStreams.push(stream);
stream.getTracks().forEach(function (track) {
track.addEventListener('ended', function () {
if (isAllTracksEnded(stream)) {
self._removeStream(stream);
}
});
});
self.emit('localStream', stream);
if (cb) {
return cb(null, stream);
}
}).catch(function (err) {
// Fallback for users without a camera
if (self.config.audioFallback && err.name === 'NotFoundError' && constraints.video !== false) {
constraints.video = false;
self.start(constraints, cb);
return;
}
self.emit('localStreamRequestFailed', constraints);