peer-data
Advanced tools
Comparing version 1.1.12 to 1.1.13
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("socket.io-client")):"function"==typeof define&&define.amd?define(["exports","socket.io-client"],t):t(e["peer-data"]=e["peer-data"]||{},e.io)}(this,function(e,t){"use strict";var n={},r=function(){function e(){}return e.register=function(e,t){n[e]||(n[e]=[]),n[e].push(t)},e.dispatch=function(e,t){n[e].forEach(function(e){return e(t)})},e}(),o=function(){function e(){}return e}();o.CONNECT="CONNECT",o.DISCONNECT="DISCONNECT",o.CANDIDATE="CANDIDATE",o.OFFER="OFFER",o.ANSWER="ANSWER",o.ERROR="ERROR";var i=function(){function e(e,t){void 0===e&&(e={}),void 0===t&&(t=null),this._servers={},this._dataConstraints=null,this._peers={},this._channels={},this._servers=e,this._dataConstraints=t}return Object.defineProperty(e.prototype,"peers",{get:function(){return this._peers},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"channels",{get:function(){return this._channels},enumerable:!0,configurable:!0}),e.prototype.addPeer=function(e,t){return this._peers.hasOwnProperty(e)||(this._peers[e]=t),this},e.prototype.removePeer=function(e){return this._peers.hasOwnProperty(e)&&(this._peers[e].close(),delete this._peers[e],delete this._peers[e]),this},e.prototype.addChannel=function(e,t){return this._channels.hasOwnProperty(e)||(this._channels[e]=t),this},e.prototype.removeChannel=function(e){return this._channels.hasOwnProperty(e)&&(this._channels[e].close(),delete this._channels[e]),this},Object.defineProperty(e.prototype,"servers",{get:function(){return this._servers},set:function(e){this._servers=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"dataConstraints",{get:function(){return this._dataConstraints},set:function(e){this._dataConstraints=e},enumerable:!0,configurable:!0}),e}(),s=function(){function e(){}return e}();s.LOG="LOG",s.OPEN="OPEN",s.CLOSE="CLOSE",s.ERROR="ERROR",s.DATA="DATA";var c=function(){function e(){}return e.get=function(e,t){var n=new RTCPeerConnection(e);return n.onicecandidate=function(e){if(e.candidate){var n={type:o.CANDIDATE,caller:null,callee:t.caller,room:t.room,data:e.candidate};r.dispatch("send",n)}},n},e}(),a=function(){function e(){}return e.get=function(e,t){var n=Math.floor(1e16*(1+Math.random())).toString(16).substring(1);return e.createDataChannel(n,t)},e.subscribeToEvents=function(e,t,n){return e.onmessage=function(e){var t={caller:n.caller,room:n.room,data:e.data};r.dispatch(s.DATA,t)},e.onopen=function(e){var t={caller:n.caller,room:n.room,data:e.type};r.dispatch(s.OPEN,t)},e.onclose=function(e){var o={caller:n.caller,room:n.room,data:e.type};r.dispatch(s.CLOSE,o),delete t[n.caller.id]},e.onerror=function(e){var t={caller:n.caller,room:n.room,data:e.type};r.dispatch(s.ERROR,t)},e},e}(),l=function(){function e(e){this._peers={},this._channels={},this._connection=e,this._peers=this._connection.peers,this._channels=this._connection.channels,r.register(o.CONNECT,this.onConnect.bind(this)),r.register(o.DISCONNECT,this.onDisconnect.bind(this)),r.register(o.OFFER,this.onOffer.bind(this)),r.register(o.ANSWER,this.onAnswer.bind(this)),r.register(o.CANDIDATE,this.onCandidate.bind(this))}return Object.defineProperty(e.prototype,"connection",{get:function(){return this._connection},set:function(e){this._connection=e},enumerable:!0,configurable:!0}),e.prototype.setLocalDescription=function(e,t){return e.setLocalDescription(t)},e.prototype.onConnect=function(e){var t=this,n=this._peers[e.caller.id]=c.get(this._connection.servers,e),r=a.get(n,this._connection.dataConstraints);this._channels[e.caller.id]=a.subscribeToEvents(r,this._channels,e),this._peers[e.caller.id]=n,n.createOffer(function(r){var i={type:o.OFFER,caller:null,callee:e.caller,room:e.room,data:r};t.setLocalDescription(n,r).then(function(){return t.dispatchEvent(i)},function(n){return t.dispatchError(e,n)})},function(n){return t.dispatchError(e,n)})},e.prototype.onDisconnect=function(e){var t=this._channels[e.caller.id],n=this._peers[e.caller.id];t.close(),n.close(),delete this._channels[e.caller.id],delete this._peers[e.caller.id]},e.prototype.onOffer=function(e){var t=this,n=c.get(this._connection.servers,e);this._peers[e.caller.id]=n,n.ondatachannel=function(n){var r=a.subscribeToEvents(n.channel,t._channels,e);t._connection.addChannel(e.caller.id,r)},n.setRemoteDescription(new RTCSessionDescription(e.data),function(){},function(n){return t.dispatchError(e,n)}),n.createAnswer(function(r){var i={type:o.ANSWER,caller:null,callee:e.caller,room:e.room,data:r};t.setLocalDescription(n,r).then(function(){return t.dispatchEvent(i)},function(n){return t.dispatchError(e,n)})},function(n){return t.dispatchError(e,n)})},e.prototype.onAnswer=function(e){var t=this;this._peers[e.caller.id].setRemoteDescription(new RTCSessionDescription(e.data),function(){},function(n){return t.dispatchError(e,n)})},e.prototype.onCandidate=function(e){var t=this,n=this._peers[e.caller.id],r=new RTCIceCandidate(e.data);n.addIceCandidate(r).then(function(){},function(n){return t.dispatchError(e,n)})},e.prototype.dispatchEvent=function(e){r.dispatch("send",e)},e.prototype.dispatchError=function(e,t){var n={caller:e.caller,room:e.room,data:t.message};r.dispatch(s.ERROR,n)},e}(),h=function(){function e(e,t){void 0===e&&(e={}),void 0===t&&(t=null);var n=new i(e,t);this.bridge=new l(n)}return e.prototype.on=function(e,t){r.register(e,t)},e.prototype.send=function(e,t){if(t){var n=this.bridge.connection.channels[t];n&&"open"===n.readyState&&n.send(e)}else Object.entries(this.bridge.connection.channels).forEach(function(t){var n=(t[0],t[1]);"open"===n.readyState&&n.send(e)})},e.prototype.connect=function(e){var t={type:o.CONNECT,caller:null,callee:null,room:{id:e},data:null};r.dispatch("send",t)},e.prototype.disconnect=function(e){Object.entries(this.bridge.connection.channels).forEach(function(e){e[0];return e[1].close()}),Object.entries(this.bridge.connection.peers).forEach(function(e){e[0];return e[1].close()});var t={type:o.DISCONNECT,caller:null,callee:null,room:{id:e},data:null};r.dispatch("send",t)},e.prototype.peers=function(e){return e?this.bridge.connection.peers[e]:this.bridge.connection.peers},e.prototype.channels=function(e){return e?this.bridge.connection.channels[e]:this.bridge.connection.channels},e}(),u=function(){function e(e){this.socket=t.connect(e),this.subscribeEvents()}return e.prototype.onSend=function(e){this.socket.emit("message",e)},e.prototype.subscribeEvents=function(){this.socket.on("message",this.onMessage.bind(this)),this.socket.on("ipaddr",this.onIp.bind(this)),this.socket.on("log",this.onLog.bind(this)),r.register("send",this.onSend.bind(this))},e.prototype.onIp=function(e){r.dispatch(s.LOG,"Server IP address is: "+e)},e.prototype.onLog=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];r.dispatch(s.LOG,e)},e.prototype.onMessage=function(e){r.dispatch(e.type,e)},e}();e.default=h,e.EventDispatcher=r,e.ConnectionEventType=o,e.DataEventType=s,e.SocketChannel=u,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("socket.io-client")):"function"==typeof define&&define.amd?define(["exports","socket.io-client"],t):t(e["peer-data"]=e["peer-data"]||{},e.io)}(this,function(e,t){"use strict";var n={},r=function(){function e(){}return e.register=function(e,t){n[e]||(n[e]=[]),n[e].push(t)},e.dispatch=function(e,t){n[e].forEach(function(e){return e(t)})},e}(),o=function(){function e(){}return e}();o.CONNECT="CONNECT",o.DISCONNECT="DISCONNECT",o.CANDIDATE="CANDIDATE",o.OFFER="OFFER",o.ANSWER="ANSWER",o.ERROR="ERROR";var i=function(){function e(e,t){void 0===e&&(e={}),void 0===t&&(t=null),this._servers={},this._dataConstraints=null,this._peers={},this._channels={},this._servers=e,this._dataConstraints=t}return Object.defineProperty(e.prototype,"peers",{get:function(){return this._peers},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"channels",{get:function(){return this._channels},enumerable:!0,configurable:!0}),e.prototype.addPeer=function(e,t){return this._peers.hasOwnProperty(e)||(this._peers[e]=t),this},e.prototype.removePeer=function(e){return this._peers.hasOwnProperty(e)&&(this._peers[e].close(),delete this._peers[e],delete this._peers[e]),this},e.prototype.addChannel=function(e,t){return this._channels.hasOwnProperty(e)||(this._channels[e]=t),this},e.prototype.removeChannel=function(e){return this._channels.hasOwnProperty(e)&&(this._channels[e].close(),delete this._channels[e]),this},Object.defineProperty(e.prototype,"servers",{get:function(){return this._servers},set:function(e){this._servers=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"dataConstraints",{get:function(){return this._dataConstraints},set:function(e){this._dataConstraints=e},enumerable:!0,configurable:!0}),e}(),s=function(){function e(){}return e}();s.LOG="LOG",s.OPEN="OPEN",s.CLOSE="CLOSE",s.ERROR="ERROR",s.DATA="DATA";var c=function(){function e(){}return e.get=function(e,t){var n=new RTCPeerConnection(e);return n.onicecandidate=function(e){if(e.candidate){var n={type:o.CANDIDATE,caller:null,callee:t.caller,room:t.room,data:e.candidate};r.dispatch("send",n)}},n},e}(),a=function(){function e(){}return e.get=function(e,t){var n=Math.floor(1e16*(1+Math.random())).toString(16).substring(1);return e.createDataChannel(n,t)},e.subscribeToEvents=function(e,t,n){return e.onmessage=function(e){var t={caller:n.caller,room:n.room,data:e.data};r.dispatch(s.DATA,t)},e.onopen=function(e){var t={caller:n.caller,room:n.room,data:e.type};r.dispatch(s.OPEN,t)},e.onclose=function(e){var o={caller:n.caller,room:n.room,data:e.type};r.dispatch(s.CLOSE,o),delete t[n.caller.id]},e.onerror=function(e){var t={caller:n.caller,room:n.room,data:e.type};r.dispatch(s.ERROR,t)},e},e}(),h=function(){function e(e){this._peers={},this._channels={},this._connection=e,this._peers=this._connection.peers,this._channels=this._connection.channels,r.register(o.CONNECT,this.onConnect.bind(this)),r.register(o.DISCONNECT,this.onDisconnect.bind(this)),r.register(o.OFFER,this.onOffer.bind(this)),r.register(o.ANSWER,this.onAnswer.bind(this)),r.register(o.CANDIDATE,this.onCandidate.bind(this))}return Object.defineProperty(e.prototype,"connection",{get:function(){return this._connection},set:function(e){this._connection=e},enumerable:!0,configurable:!0}),e.prototype.onNewPeer=function(e){},e.prototype.setLocalDescription=function(e,t){return e.setLocalDescription(t)},e.prototype.setRemoteDescription=function(e,t){return e.setRemoteDescription(t)},e.prototype.onConnect=function(e){var t=this,n=this._peers[e.caller.id]=c.get(this._connection.servers,e),r=a.get(n,this._connection.dataConstraints);this._channels[e.caller.id]=a.subscribeToEvents(r,this._channels,e),this._peers[e.caller.id]=n,this.onNewPeer(n),n.createOffer(function(r){var i={type:o.OFFER,caller:null,callee:e.caller,room:e.room,data:r};t.setLocalDescription(n,r).then(function(){return t.dispatchEvent(i)},function(n){return t.dispatchError(e,n)})},function(n){return t.dispatchError(e,n)})},e.prototype.onDisconnect=function(e){var t=this._channels[e.caller.id],n=this._peers[e.caller.id];t.close(),n.close(),delete this._channels[e.caller.id],delete this._peers[e.caller.id]},e.prototype.onOffer=function(e){var t=this,n=c.get(this._connection.servers,e);this._peers[e.caller.id]=n,this.onNewPeer(n),n.ondatachannel=function(n){var r=a.subscribeToEvents(n.channel,t._channels,e);t._connection.addChannel(e.caller.id,r)},this.setRemoteDescription(n,new RTCSessionDescription(e.data)).then(function(){},function(n){return t.dispatchError(e,n)}),n.createAnswer(function(r){var i={type:o.ANSWER,caller:null,callee:e.caller,room:e.room,data:r};t.setLocalDescription(n,r).then(function(){return t.dispatchEvent(i)},function(n){return t.dispatchError(e,n)})},function(n){return t.dispatchError(e,n)})},e.prototype.onAnswer=function(e){var t=this,n=this._peers[e.caller.id];this.setRemoteDescription(n,new RTCSessionDescription(e.data)).then(function(){},function(n){return t.dispatchError(e,n)})},e.prototype.onCandidate=function(e){var t=this,n=this._peers[e.caller.id],r=new RTCIceCandidate(e.data);n.addIceCandidate(r).then(function(){},function(n){return t.dispatchError(e,n)})},e.prototype.dispatchEvent=function(e){r.dispatch("send",e)},e.prototype.dispatchError=function(e,t){var n={caller:e.caller,room:e.room,data:t.message};r.dispatch(s.ERROR,n)},e}(),l=function(){function e(e,t){void 0===e&&(e={}),void 0===t&&(t=null);var n=new i(e,t);this.bridge=new h(n)}return e.prototype.on=function(e,t){r.register(e,t)},e.prototype.send=function(e,t){if(t){var n=this.bridge.connection.channels[t];n&&"open"===n.readyState&&n.send(e)}else Object.entries(this.bridge.connection.channels).forEach(function(t){var n=(t[0],t[1]);"open"===n.readyState&&n.send(e)})},e.prototype.connect=function(e){var t={type:o.CONNECT,caller:null,callee:null,room:{id:e},data:null};r.dispatch("send",t)},e.prototype.disconnect=function(e){Object.entries(this.bridge.connection.channels).forEach(function(e){e[0];return e[1].close()}),Object.entries(this.bridge.connection.peers).forEach(function(e){e[0];return e[1].close()});var t={type:o.DISCONNECT,caller:null,callee:null,room:{id:e},data:null};r.dispatch("send",t)},e.prototype.peers=function(e){return e?this.bridge.connection.peers[e]:this.bridge.connection.peers},e.prototype.channels=function(e){return e?this.bridge.connection.channels[e]:this.bridge.connection.channels},e}(),u=function(){function e(e){this.socket=t.connect(e),this.subscribeEvents()}return e.prototype.onSend=function(e){this.socket.emit("message",e)},e.prototype.subscribeEvents=function(){this.socket.on("message",this.onMessage.bind(this)),this.socket.on("ipaddr",this.onIp.bind(this)),this.socket.on("log",this.onLog.bind(this)),r.register("send",this.onSend.bind(this))},e.prototype.onIp=function(e){r.dispatch(s.LOG,"Server IP address is: "+e)},e.prototype.onLog=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];r.dispatch(s.LOG,e)},e.prototype.onMessage=function(e){r.dispatch(e.type,e)},e}();e.default=l,e.EventDispatcher=r,e.ConnectionEventType=o,e.DataEventType=s,e.SocketChannel=u,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=peer-data.js.map |
@@ -9,3 +9,5 @@ import { Connection } from './connection/connection'; | ||
connection: Connection; | ||
onNewPeer(peer: RTCPeerConnection): void; | ||
setLocalDescription(peer: RTCPeerConnection, desc: RTCSessionDescription): Promise<void>; | ||
setRemoteDescription(peer: RTCPeerConnection, desc: RTCSessionDescription): Promise<void>; | ||
onConnect(event: ConnectionEvent): void; | ||
@@ -12,0 +14,0 @@ onDisconnect(event: ConnectionEvent): void; |
@@ -29,5 +29,9 @@ import { EventDispatcher } from './dispatcher/dispatcher'; | ||
}); | ||
Bridge.prototype.onNewPeer = function (peer) { }; | ||
Bridge.prototype.setLocalDescription = function (peer, desc) { | ||
return peer.setLocalDescription(desc); | ||
}; | ||
Bridge.prototype.setRemoteDescription = function (peer, desc) { | ||
return peer.setRemoteDescription(desc); | ||
}; | ||
Bridge.prototype.onConnect = function (event) { | ||
@@ -39,2 +43,3 @@ var _this = this; | ||
this._peers[event.caller.id] = peer; | ||
this.onNewPeer(peer); | ||
peer.createOffer(function (desc) { | ||
@@ -63,2 +68,3 @@ var message = { | ||
this._peers[event.caller.id] = peer; | ||
this.onNewPeer(peer); | ||
peer.ondatachannel = function (dataChannelEvent) { | ||
@@ -68,3 +74,3 @@ var channel = DataChannelFactory.subscribeToEvents(dataChannelEvent.channel, _this._channels, event); | ||
}; | ||
peer.setRemoteDescription(new RTCSessionDescription(event.data), function () { }, function (evnt) { return _this.dispatchError(event, evnt); }); | ||
this.setRemoteDescription(peer, new RTCSessionDescription(event.data)).then(function () { }, function (evnt) { return _this.dispatchError(event, evnt); }); | ||
peer.createAnswer(function (desc) { | ||
@@ -84,3 +90,3 @@ var message = { | ||
var peer = this._peers[event.caller.id]; | ||
peer.setRemoteDescription(new RTCSessionDescription(event.data), function () { }, function (evnt) { return _this.dispatchError(event, evnt); }); | ||
this.setRemoteDescription(peer, new RTCSessionDescription(event.data)).then(function () { }, function (evnt) { return _this.dispatchError(event, evnt); }); | ||
}; | ||
@@ -87,0 +93,0 @@ Bridge.prototype.onCandidate = function (event) { |
@@ -9,3 +9,5 @@ import { Connection } from './connection/connection'; | ||
connection: Connection; | ||
onNewPeer(peer: RTCPeerConnection): void; | ||
setLocalDescription(peer: RTCPeerConnection, desc: RTCSessionDescription): Promise<void>; | ||
setRemoteDescription(peer: RTCPeerConnection, desc: RTCSessionDescription): Promise<void>; | ||
onConnect(event: ConnectionEvent): void; | ||
@@ -12,0 +14,0 @@ onDisconnect(event: ConnectionEvent): void; |
@@ -31,5 +31,9 @@ "use strict"; | ||
}); | ||
Bridge.prototype.onNewPeer = function (peer) { }; | ||
Bridge.prototype.setLocalDescription = function (peer, desc) { | ||
return peer.setLocalDescription(desc); | ||
}; | ||
Bridge.prototype.setRemoteDescription = function (peer, desc) { | ||
return peer.setRemoteDescription(desc); | ||
}; | ||
Bridge.prototype.onConnect = function (event) { | ||
@@ -41,2 +45,3 @@ var _this = this; | ||
this._peers[event.caller.id] = peer; | ||
this.onNewPeer(peer); | ||
peer.createOffer(function (desc) { | ||
@@ -65,2 +70,3 @@ var message = { | ||
this._peers[event.caller.id] = peer; | ||
this.onNewPeer(peer); | ||
peer.ondatachannel = function (dataChannelEvent) { | ||
@@ -70,3 +76,3 @@ var channel = factory_2.DataChannelFactory.subscribeToEvents(dataChannelEvent.channel, _this._channels, event); | ||
}; | ||
peer.setRemoteDescription(new RTCSessionDescription(event.data), function () { }, function (evnt) { return _this.dispatchError(event, evnt); }); | ||
this.setRemoteDescription(peer, new RTCSessionDescription(event.data)).then(function () { }, function (evnt) { return _this.dispatchError(event, evnt); }); | ||
peer.createAnswer(function (desc) { | ||
@@ -86,3 +92,3 @@ var message = { | ||
var peer = this._peers[event.caller.id]; | ||
peer.setRemoteDescription(new RTCSessionDescription(event.data), function () { }, function (evnt) { return _this.dispatchError(event, evnt); }); | ||
this.setRemoteDescription(peer, new RTCSessionDescription(event.data)).then(function () { }, function (evnt) { return _this.dispatchError(event, evnt); }); | ||
}; | ||
@@ -89,0 +95,0 @@ Bridge.prototype.onCandidate = function (event) { |
{ | ||
"name": "peer-data", | ||
"version": "1.1.12", | ||
"version": "1.1.13", | ||
"description": "PeerData - library for files, media streaming/sharing using WebRTC", | ||
@@ -5,0 +5,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
247921
1368