peer-data
Advanced tools
Comparing version 1.1.7 to 1.1.8
@@ -11,2 +11,4 @@ // Generated by dts-bundle v0.7.2 | ||
disconnect(roomId?: string): void; | ||
peers(id?: string): PeerCollection | RTCPeerConnection; | ||
channels(id?: string): DataChannelCollection | RTCDataChannel; | ||
} | ||
@@ -58,2 +60,10 @@ | ||
export interface PeerCollection { | ||
[index: string]: RTCPeerConnection; | ||
} | ||
export interface DataChannelCollection { | ||
[index: string]: RTCDataChannel; | ||
} | ||
export type EventHandler = (data?: any) => any; | ||
@@ -60,0 +70,0 @@ |
@@ -1,2 +0,2 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("socket.io-client")):"function"==typeof define&&define.amd?define(["exports","socket.io-client"],n):n(e["peer-data"]=e["peer-data"]||{},e.io)}(this,function(e,n){"use strict";var t={},r=function(){function e(){}return e.register=function(e,n){t[e]||(t[e]=[]),t[e].push(n)},e.dispatch=function(e,n){t[e].forEach(function(e){return e(n)})},e}(),i=function(){function e(){}return e}();i.CONNECT="CONNECT",i.DISCONNECT="DISCONNECT",i.CANDIDATE="CANDIDATE",i.OFFER="OFFER",i.ANSWER="ANSWER",i.ERROR="ERROR";var o=function(){function e(e,n){void 0===e&&(e={}),void 0===n&&(n=null),this._servers={},this._dataConstraints=null,this._peers={},this._channels={},this._servers=e,this._dataConstraints=n}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,n){return this._peers.hasOwnProperty(e)||(this._peers[e]=n),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,n){return this._channels.hasOwnProperty(e)||(this._channels[e]=n),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,n){var t=new RTCPeerConnection(e);return t.onicecandidate=function(e){if(e.candidate){var t={type:i.CANDIDATE,caller:null,callee:n.caller,room:n.room,data:e.candidate};r.dispatch("send",t)}},t},e}(),a=function(){function e(){}return e.get=function(e,n){var t=Math.floor(1e16*(1+Math.random())).toString(16).substring(1);return e.createDataChannel(t,n)},e.subscribeToEvents=function(e,n,t){return e.onmessage=function(e){var n={id:t.caller.id,event:e};r.dispatch(s.DATA,n)},e.onopen=function(e){var n={id:t.caller.id,event:e};r.dispatch(s.OPEN,n)},e.onclose=function(e){var i={id:t.caller.id,event:e};r.dispatch(s.CLOSE,i),delete n[t.caller.id]},e.onerror=function(e){var n={id:t.caller.id,event:e};r.dispatch(s.ERROR,n)},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(i.CONNECT,this.onConnect.bind(this)),r.register(i.DISCONNECT,this.onDisconnect.bind(this)),r.register(i.OFFER,this.onOffer.bind(this)),r.register(i.ANSWER,this.onAnswer.bind(this)),r.register(i.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.onConnect=function(e){var n=this,t=this._peers[e.caller.id]=c.get(this._connection.servers,e),r=a.get(t,this._connection.dataConstraints);this._channels[e.caller.id]=a.subscribeToEvents(r,this._channels,e),this._peers[e.caller.id]=t,t.createOffer(function(r){var o={type:i.OFFER,caller:null,callee:e.caller,room:e.room,data:r};t.setLocalDescription(r,function(){return n.dispatchEvent(o)},function(t){return n.dispatchError(e.caller,t)})},function(t){return n.dispatchError(e.caller,t)})},e.prototype.onDisconnect=function(e){var n=this._channels[e.caller.id],t=this._peers[e.caller.id];n.close(),t.close(),delete this._channels[e.caller.id],delete this._peers[e.caller.id]},e.prototype.onOffer=function(e){var n=this,t=c.get(this._connection.servers,e);this._peers[e.caller.id]=t,t.ondatachannel=function(t){var r=a.subscribeToEvents(t.channel,n._channels,e);n._connection.addChannel(e.caller.id,r)},t.setRemoteDescription(new RTCSessionDescription(e.data),function(){},function(t){return n.dispatchError(e.caller,t)}),t.createAnswer(function(r){var o={type:i.ANSWER,caller:null,callee:e.caller,room:e.room,data:r};t.setLocalDescription(r,function(){return n.dispatchEvent(o)},function(t){return n.dispatchError(e.caller,t)})},function(t){return n.dispatchError(e.caller,t)})},e.prototype.onAnswer=function(e){var n=this;this._peers[e.caller.id].setRemoteDescription(new RTCSessionDescription(e.data),function(){},function(t){return n.dispatchError(e.caller,t)})},e.prototype.onCandidate=function(e){var n=this,t=this._peers[e.caller.id],r=new RTCIceCandidate(e.data);t.addIceCandidate(r).then(function(){},function(t){return n.dispatchError(e.caller,t)})},e.prototype.dispatchEvent=function(e){r.dispatch("send",e)},e.prototype.dispatchError=function(e,n){var t={id:e.id,event:n};r.dispatch(s.ERROR,t)},e}(),h=function(){function e(e,n){void 0===e&&(e={}),void 0===n&&(n=null);var t=new o(e,n);this.bridge=new l(t)}return e.prototype.on=function(e,n){r.register(e,n)},e.prototype.send=function(e,n){if(n){var t=this.bridge.connection.channels[n];t&&t.send(e)}else Object.entries(this.bridge.connection.channels).forEach(function(n){n[0];return n[1].send(e)})},e.prototype.connect=function(e){var n={type:i.CONNECT,caller:null,callee:null,room:{id:e},data:null};r.dispatch("send",n)},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 n={type:i.DISCONNECT,caller:null,callee:null,room:{id:e},data:null};r.dispatch("send",n)},e}(),u=function(){function e(e){this.socket=n.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=[],n=0;n<arguments.length;n++)e[n]=arguments[n];r.dispatch(s.LOG,e)},e.prototype.onMessage=function(e){r.dispatch(e.type,e)},e}();e.default=h,e.EventDispatcher=r,e.ConnectionEventType=i,e.DataEventType=s,e.SocketChannel=u,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("socket.io-client")):"function"==typeof define&&define.amd?define(["exports","socket.io-client"],n):n(e["peer-data"]=e["peer-data"]||{},e.io)}(this,function(e,n){"use strict";var t={},r=function(){function e(){}return e.register=function(e,n){t[e]||(t[e]=[]),t[e].push(n)},e.dispatch=function(e,n){t[e].forEach(function(e){return e(n)})},e}(),i=function(){function e(){}return e}();i.CONNECT="CONNECT",i.DISCONNECT="DISCONNECT",i.CANDIDATE="CANDIDATE",i.OFFER="OFFER",i.ANSWER="ANSWER",i.ERROR="ERROR";var o=function(){function e(e,n){void 0===e&&(e={}),void 0===n&&(n=null),this._servers={},this._dataConstraints=null,this._peers={},this._channels={},this._servers=e,this._dataConstraints=n}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,n){return this._peers.hasOwnProperty(e)||(this._peers[e]=n),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,n){return this._channels.hasOwnProperty(e)||(this._channels[e]=n),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,n){var t=new RTCPeerConnection(e);return t.onicecandidate=function(e){if(e.candidate){var t={type:i.CANDIDATE,caller:null,callee:n.caller,room:n.room,data:e.candidate};r.dispatch("send",t)}},t},e}(),a=function(){function e(){}return e.get=function(e,n){var t=Math.floor(1e16*(1+Math.random())).toString(16).substring(1);return e.createDataChannel(t,n)},e.subscribeToEvents=function(e,n,t){return e.onmessage=function(e){var n={id:t.caller.id,event:e};r.dispatch(s.DATA,n)},e.onopen=function(e){var n={id:t.caller.id,event:e};r.dispatch(s.OPEN,n)},e.onclose=function(e){var i={id:t.caller.id,event:e};r.dispatch(s.CLOSE,i),delete n[t.caller.id]},e.onerror=function(e){var n={id:t.caller.id,event:e};r.dispatch(s.ERROR,n)},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(i.CONNECT,this.onConnect.bind(this)),r.register(i.DISCONNECT,this.onDisconnect.bind(this)),r.register(i.OFFER,this.onOffer.bind(this)),r.register(i.ANSWER,this.onAnswer.bind(this)),r.register(i.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.onConnect=function(e){var n=this,t=this._peers[e.caller.id]=c.get(this._connection.servers,e),r=a.get(t,this._connection.dataConstraints);this._channels[e.caller.id]=a.subscribeToEvents(r,this._channels,e),this._peers[e.caller.id]=t,t.createOffer(function(r){var o={type:i.OFFER,caller:null,callee:e.caller,room:e.room,data:r};t.setLocalDescription(r,function(){return n.dispatchEvent(o)},function(t){return n.dispatchError(e.caller,t)})},function(t){return n.dispatchError(e.caller,t)})},e.prototype.onDisconnect=function(e){var n=this._channels[e.caller.id],t=this._peers[e.caller.id];n.close(),t.close(),delete this._channels[e.caller.id],delete this._peers[e.caller.id]},e.prototype.onOffer=function(e){var n=this,t=c.get(this._connection.servers,e);this._peers[e.caller.id]=t,t.ondatachannel=function(t){var r=a.subscribeToEvents(t.channel,n._channels,e);n._connection.addChannel(e.caller.id,r)},t.setRemoteDescription(new RTCSessionDescription(e.data),function(){},function(t){return n.dispatchError(e.caller,t)}),t.createAnswer(function(r){var o={type:i.ANSWER,caller:null,callee:e.caller,room:e.room,data:r};t.setLocalDescription(r,function(){return n.dispatchEvent(o)},function(t){return n.dispatchError(e.caller,t)})},function(t){return n.dispatchError(e.caller,t)})},e.prototype.onAnswer=function(e){var n=this;this._peers[e.caller.id].setRemoteDescription(new RTCSessionDescription(e.data),function(){},function(t){return n.dispatchError(e.caller,t)})},e.prototype.onCandidate=function(e){var n=this,t=this._peers[e.caller.id],r=new RTCIceCandidate(e.data);t.addIceCandidate(r).then(function(){},function(t){return n.dispatchError(e.caller,t)})},e.prototype.dispatchEvent=function(e){r.dispatch("send",e)},e.prototype.dispatchError=function(e,n){var t={id:e.id,event:n};r.dispatch(s.ERROR,t)},e}(),h=function(){function e(e,n){void 0===e&&(e={}),void 0===n&&(n=null);var t=new o(e,n);this.bridge=new l(t)}return e.prototype.on=function(e,n){r.register(e,n)},e.prototype.send=function(e,n){if(n){var t=this.bridge.connection.channels[n];t&&"open"===t.readyState&&t.send(e)}else Object.entries(this.bridge.connection.channels).forEach(function(n){var t=(n[0],n[1]);"open"===t.readyState&&t.send(e)})},e.prototype.connect=function(e){var n={type:i.CONNECT,caller:null,callee:null,room:{id:e},data:null};r.dispatch("send",n)},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 n={type:i.DISCONNECT,caller:null,callee:null,room:{id:e},data:null};r.dispatch("send",n)},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=n.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=[],n=0;n<arguments.length;n++)e[n]=arguments[n];r.dispatch(s.LOG,e)},e.prototype.onMessage=function(e){r.dispatch(e.type,e)},e}();e.default=h,e.EventDispatcher=r,e.ConnectionEventType=i,e.DataEventType=s,e.SocketChannel=u,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=peer-data.js.map |
import { EventHandler } from './dispatcher/handler'; | ||
import { PeerCollection } from './peer/collection'; | ||
import { DataChannelCollection } from './channel/collection'; | ||
export declare class App { | ||
@@ -9,2 +11,4 @@ private bridge; | ||
disconnect(roomId?: string): void; | ||
peers(id?: string): PeerCollection | RTCPeerConnection; | ||
channels(id?: string): DataChannelCollection | RTCDataChannel; | ||
} |
@@ -18,3 +18,3 @@ import { EventDispatcher } from './dispatcher/dispatcher'; | ||
var channel = this.bridge.connection.channels[id]; | ||
if (channel) { | ||
if (channel && channel.readyState === 'open') { | ||
channel.send(data); | ||
@@ -28,3 +28,5 @@ } | ||
var key = _a[0], value = _a[1]; | ||
return value.send(data); | ||
if (value.readyState === 'open') { | ||
value.send(data); | ||
} | ||
}); | ||
@@ -65,2 +67,14 @@ } | ||
}; | ||
App.prototype.peers = function (id) { | ||
if (id) { | ||
return this.bridge.connection.peers[id]; | ||
} | ||
return this.bridge.connection.peers; | ||
}; | ||
App.prototype.channels = function (id) { | ||
if (id) { | ||
return this.bridge.connection.channels[id]; | ||
} | ||
return this.bridge.connection.channels; | ||
}; | ||
return App; | ||
@@ -67,0 +81,0 @@ }()); |
@@ -10,1 +10,3 @@ import { App as PeerData } from './app/app'; | ||
export { SocketChannel } from './app/signaling/socket-channel'; | ||
export { PeerCollection } from './app/peer/collection'; | ||
export { DataChannelCollection } from './app/channel/collection'; |
import { EventHandler } from './dispatcher/handler'; | ||
import { PeerCollection } from './peer/collection'; | ||
import { DataChannelCollection } from './channel/collection'; | ||
export declare class App { | ||
@@ -9,2 +11,4 @@ private bridge; | ||
disconnect(roomId?: string): void; | ||
peers(id?: string): PeerCollection | RTCPeerConnection; | ||
channels(id?: string): DataChannelCollection | RTCDataChannel; | ||
} |
@@ -20,3 +20,3 @@ "use strict"; | ||
var channel = this.bridge.connection.channels[id]; | ||
if (channel) { | ||
if (channel && channel.readyState === 'open') { | ||
channel.send(data); | ||
@@ -30,3 +30,5 @@ } | ||
var key = _a[0], value = _a[1]; | ||
return value.send(data); | ||
if (value.readyState === 'open') { | ||
value.send(data); | ||
} | ||
}); | ||
@@ -67,2 +69,14 @@ } | ||
}; | ||
App.prototype.peers = function (id) { | ||
if (id) { | ||
return this.bridge.connection.peers[id]; | ||
} | ||
return this.bridge.connection.peers; | ||
}; | ||
App.prototype.channels = function (id) { | ||
if (id) { | ||
return this.bridge.connection.channels[id]; | ||
} | ||
return this.bridge.connection.channels; | ||
}; | ||
return App; | ||
@@ -69,0 +83,0 @@ }()); |
@@ -10,1 +10,3 @@ import { App as PeerData } from './app/app'; | ||
export { SocketChannel } from './app/signaling/socket-channel'; | ||
export { PeerCollection } from './app/peer/collection'; | ||
export { DataChannelCollection } from './app/channel/collection'; |
{ | ||
"name": "peer-data", | ||
"version": "1.1.7", | ||
"version": "1.1.8", | ||
"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
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
243833
1326