peer-data
Advanced tools
Comparing version 1.2.1 to 1.2.3
@@ -15,2 +15,3 @@ // Generated by dts-bundle v0.7.2 | ||
export const HANDLERS: EventHandlerCollection; | ||
export class EventDispatcher { | ||
@@ -64,2 +65,6 @@ static register(type: any, callback: EventHandler): void; | ||
export interface EventHandlerCollection { | ||
[index: string]: EventHandler[]; | ||
} | ||
export interface Caller { | ||
@@ -66,0 +71,0 @@ id: string; |
@@ -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}(),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,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){var t=this;return this._peers.hasOwnProperty(e)||(this._peers[e]=n,n.onconnectionstatechange=function(r){"closed"===n.connectionState&&t.removePeer(e)}),this},e.prototype.getPeer=function(e){return this._peers.hasOwnProperty(e)?this._peers[e]:null},e.prototype.removePeer=function(e){return this._peers.hasOwnProperty(e)&&(this._peers[e].close(),delete this._peers[e]),this},e.prototype.addChannel=function(e,n){var t=this;return this._channels.hasOwnProperty(e)||(this._channels[e]=n,n.onclose=function(n){return t.removeChannel(e)}),this},e.prototype.getChannel=function(e){return this._channels.hasOwnProperty(e)?this._channels[e]:null},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}(),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:o.CANDIDATE,caller:null,callee:n.caller,room:n.room,data:e.candidate};r.dispatch("send",t)}},t},e}(),s=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}(),a=function(){function e(){}return e}();a.LOG="LOG",a.ERROR="ERROR",a.PEER="PEER",a.CHANNEL="CHANNEL";var h=function(){function e(e){this._connection=e,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.onConnect=function(e){var n=this,t=c.get(this._connection.servers,e),r=s.get(t,this._connection.dataConstraints);this.dispatchPeer(t,e),this.dispatchChannel(r,e),this._connection.addChannel(e.caller.id,r),this._connection.addPeer(e.caller.id,t),t.createOffer(function(r){var i={type:o.OFFER,caller:null,callee:e.caller,room:e.room,data:r};t.setLocalDescription(r,function(){return n.dispatchEvent(i)},function(t){return n.dispatchError(e,t)})},function(t){return n.dispatchError(e,t)})},e.prototype.onDisconnect=function(e){this._connection.removeChannel(e.caller.id),this._connection.removePeer(e.caller.id)},e.prototype.onOffer=function(e){var n=this,t=c.get(this._connection.servers,e);this._connection.addPeer(e.caller.id,t),this.dispatchPeer(t,e),t.ondatachannel=function(t){n.dispatchChannel(t.channel,e),n._connection.addChannel(e.caller.id,t.channel)},t.setRemoteDescription(new RTCSessionDescription(e.data),function(){},function(t){return n.dispatchError(e,t)}),t.createAnswer(function(r){var i={type:o.ANSWER,caller:null,callee:e.caller,room:e.room,data:r};t.setLocalDescription(r,function(){return n.dispatchEvent(i)},function(t){return n.dispatchError(e,t)})},function(t){return n.dispatchError(e,t)})},e.prototype.onAnswer=function(e){var n=this;this._connection.getPeer(e.caller.id).setRemoteDescription(new RTCSessionDescription(e.data),function(){},function(t){return n.dispatchError(e,t)})},e.prototype.onCandidate=function(e){var n=this,t=this._connection.getPeer(e.caller.id),r=new RTCIceCandidate(e.data);t.addIceCandidate(r).then(function(){},function(t){return n.dispatchError(e,t)})},e.prototype.dispatchPeer=function(e,n){var t={caller:n.caller,room:n.room,data:e};r.dispatch(a.PEER,t)},e.prototype.dispatchChannel=function(e,n){var t={caller:n.caller,room:n.room,data:e};r.dispatch(a.CHANNEL,t)},e.prototype.dispatchEvent=function(e){r.dispatch("send",e)},e.prototype.dispatchError=function(e,n){var t={caller:e.caller,room:e.room,data:n.message};r.dispatch(a.ERROR,t)},e}(),u=function(){function e(e,n){void 0===e&&(e={}),void 0===n&&(n=null);var t=new i(e,n);this.bridge=new h(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:o.CONNECT,caller:null,callee:null,room:{id:e},data:null};r.dispatch("send",n)},e.prototype.disconnect=function(e){var n=this.bridge.connection;Object.entries(n.channels).forEach(function(e){var t=e[0];e[1];return n.removeChannel(t)}),Object.entries(n.peers).forEach(function(e){var t=e[0];e[1];return n.removePeer(t)});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}(),p=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(a.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(a.LOG,e)},e.prototype.onMessage=function(e){r.dispatch(e.type,e)},e}();e.default=u,e.EventDispatcher=r,e.AppEventType=a,e.SignalingEventType=o,e.SocketChannel=p,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}(),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,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){var t=this;return this._peers.hasOwnProperty(e)||(this._peers[e]=n,n.onconnectionstatechange=function(r){"closed"===n.connectionState&&t.removePeer(e)}),this},e.prototype.getPeer=function(e){return this._peers.hasOwnProperty(e)?this._peers[e]:null},e.prototype.removePeer=function(e){return this._peers.hasOwnProperty(e)&&(this._peers[e].close(),delete this._peers[e]),this},e.prototype.addChannel=function(e,n){var t=this;return this._channels.hasOwnProperty(e)||(this._channels[e]=n,n.onclose=function(n){return t.removeChannel(e)}),this},e.prototype.getChannel=function(e){return this._channels.hasOwnProperty(e)?this._channels[e]:null},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}(),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:o.CANDIDATE,caller:null,callee:n.caller,room:n.room,data:e.candidate};r.dispatch("send",t)}},t},e}(),s=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}(),a=function(){function e(){}return e}();a.LOG="LOG",a.ERROR="ERROR",a.PEER="PEER",a.CHANNEL="CHANNEL";var h=function(){function e(e){this._connection=e,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.onConnect=function(e){var n=this,t=c.get(this._connection.servers,e),r=s.get(t,this._connection.dataConstraints);this.dispatchPeer(t,e),this.dispatchChannel(r,e),this._connection.addChannel(e.caller.id,r),this._connection.addPeer(e.caller.id,t),t.createOffer(function(r){var i={type:o.OFFER,caller:null,callee:e.caller,room:e.room,data:r};t.setLocalDescription(r,function(){return n.dispatchEvent(i)},function(t){return n.dispatchError(e,t)})},function(t){return n.dispatchError(e,t)})},e.prototype.onDisconnect=function(e){this._connection.removeChannel(e.caller.id),this._connection.removePeer(e.caller.id)},e.prototype.onOffer=function(e){var n=this,t=c.get(this._connection.servers,e);this._connection.addPeer(e.caller.id,t),this.dispatchPeer(t,e),t.ondatachannel=function(t){n.dispatchChannel(t.channel,e),n._connection.addChannel(e.caller.id,t.channel)},t.setRemoteDescription(new RTCSessionDescription(e.data),function(){},function(t){return n.dispatchError(e,t)}),t.createAnswer(function(r){var i={type:o.ANSWER,caller:null,callee:e.caller,room:e.room,data:r};t.setLocalDescription(r,function(){return n.dispatchEvent(i)},function(t){return n.dispatchError(e,t)})},function(t){return n.dispatchError(e,t)})},e.prototype.onAnswer=function(e){var n=this;this._connection.getPeer(e.caller.id).setRemoteDescription(new RTCSessionDescription(e.data),function(){},function(t){return n.dispatchError(e,t)})},e.prototype.onCandidate=function(e){var n=this,t=this._connection.getPeer(e.caller.id),r=new RTCIceCandidate(e.data);t.addIceCandidate(r).then(function(){},function(t){return n.dispatchError(e,t)})},e.prototype.dispatchPeer=function(e,n){var t={caller:n.caller,room:n.room,data:e};r.dispatch(a.PEER,t)},e.prototype.dispatchChannel=function(e,n){var t={caller:n.caller,room:n.room,data:e};r.dispatch(a.CHANNEL,t)},e.prototype.dispatchEvent=function(e){r.dispatch("send",e)},e.prototype.dispatchError=function(e,n){var t={caller:e.caller,room:e.room,data:n.message};r.dispatch(a.ERROR,t)},e}(),u=function(){function e(e,n){void 0===e&&(e={}),void 0===n&&(n=null);var t=new i(e,n);this.bridge=new h(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:o.CONNECT,caller:null,callee:null,room:{id:e},data:null};r.dispatch("send",n)},e.prototype.disconnect=function(e){var n=this.bridge.connection;Object.entries(n.channels).forEach(function(e){var t=e[0];e[1];return n.removeChannel(t)}),Object.entries(n.peers).forEach(function(e){var t=e[0];e[1];return n.removePeer(t)});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}(),p=function(){function e(e){this.socket=n.connect(e),r.register("send",this.onSend.bind(this)),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))},e.prototype.onIp=function(e){r.dispatch(a.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(a.LOG,e)},e.prototype.onMessage=function(e){r.dispatch(e.type,e)},e}();e.default=u,e.EventDispatcher=r,e.AppEventType=a,e.SignalingEventType=o,e.SocketChannel=p,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=peer-data.js.map |
@@ -0,2 +1,4 @@ | ||
import { EventHandlerCollection } from './handler.collection'; | ||
import { EventHandler } from './handler'; | ||
export declare const HANDLERS: EventHandlerCollection; | ||
export declare class EventDispatcher { | ||
@@ -3,0 +5,0 @@ static register(type: any, callback: EventHandler): void; |
@@ -1,2 +0,2 @@ | ||
var HANDLERS = {}; | ||
export var HANDLERS = {}; | ||
var EventDispatcher = (function () { | ||
@@ -3,0 +3,0 @@ function EventDispatcher() { |
@@ -7,2 +7,3 @@ import * as io from 'socket.io-client'; | ||
this.socket = io.connect(opts); | ||
EventDispatcher.register('send', this.onSend.bind(this)); | ||
this.subscribeEvents(); | ||
@@ -17,3 +18,2 @@ } | ||
this.socket.on('log', this.onLog.bind(this)); | ||
EventDispatcher.register('send', this.onSend.bind(this)); | ||
}; | ||
@@ -20,0 +20,0 @@ SocketChannel.prototype.onIp = function (ipaddr) { |
#!/usr/bin/env node | ||
var semver = require('semver'); | ||
@@ -21,2 +22,5 @@ | ||
var jestConfig = { | ||
transform: { | ||
'.(ts?)': '<rootDir>/node_modules/ts-jest/preprocessor.js' | ||
}, | ||
testMatch: [ | ||
@@ -48,2 +52,2 @@ '**/__tests__/**/*.{t,j}s', | ||
console.log(JSON.stringify(jestConfig)); | ||
} | ||
} |
@@ -0,2 +1,4 @@ | ||
import { EventHandlerCollection } from './handler.collection'; | ||
import { EventHandler } from './handler'; | ||
export declare const HANDLERS: EventHandlerCollection; | ||
export declare class EventDispatcher { | ||
@@ -3,0 +5,0 @@ static register(type: any, callback: EventHandler): void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var HANDLERS = {}; | ||
exports.HANDLERS = {}; | ||
var EventDispatcher = (function () { | ||
@@ -8,9 +8,9 @@ function EventDispatcher() { | ||
EventDispatcher.register = function (type, callback) { | ||
if (!HANDLERS[type]) { | ||
HANDLERS[type] = []; | ||
if (!exports.HANDLERS[type]) { | ||
exports.HANDLERS[type] = []; | ||
} | ||
HANDLERS[type].push(callback); | ||
exports.HANDLERS[type].push(callback); | ||
}; | ||
EventDispatcher.dispatch = function (type, data) { | ||
HANDLERS[type].forEach(function (h) { return h(data); }); | ||
exports.HANDLERS[type].forEach(function (h) { return h(data); }); | ||
}; | ||
@@ -17,0 +17,0 @@ return EventDispatcher; |
@@ -9,2 +9,3 @@ "use strict"; | ||
this.socket = io.connect(opts); | ||
dispatcher_1.EventDispatcher.register('send', this.onSend.bind(this)); | ||
this.subscribeEvents(); | ||
@@ -19,3 +20,2 @@ } | ||
this.socket.on('log', this.onLog.bind(this)); | ||
dispatcher_1.EventDispatcher.register('send', this.onSend.bind(this)); | ||
}; | ||
@@ -22,0 +22,0 @@ SocketChannel.prototype.onIp = function (ipaddr) { |
{ | ||
"name": "peer-data", | ||
"version": "1.2.1", | ||
"version": "1.2.3", | ||
"description": "PeerData - library for files, media streaming/sharing using WebRTC", | ||
"scripts": { | ||
"build": "npm run build:lib & npm run build:umd", | ||
"build": "yarn run build:lib & yarn run build:umd", | ||
"build:lib": "tsc --outDir lib --module commonjs", | ||
"build:es": "tsc --outDir es --module es6", | ||
"build:umd": "npm run build:es && rollup --config && dts-bundle --name dist/bundle --main es --outputAsModuleFolder", | ||
"build:umd": "yarn run build:es && rollup --config && dts-bundle --name dist/bundle --main es --outputAsModuleFolder", | ||
"clean": "rimraf dist es lib coverage", | ||
@@ -14,8 +14,9 @@ "typecheck": "tsc --noEmit", | ||
"test": "jest --no-cache --config $(node jest.config.js)", | ||
"test:cov": "jest --coverage --no-cache --config $(node jest.config.js)", | ||
"test:watch": "jest --watch --updateSnapshot --config $(node jest.config.js)", | ||
"prepare": "npm run build", | ||
"prebuild": "npm run clean", | ||
"prepare": "yarn run build", | ||
"prebuild": "yarn run clean", | ||
"postbuild": "rimraf {lib,es}/**/__tests__", | ||
"posttest": "npm run typecheck && npm run lint", | ||
"preversion": "npm test", | ||
"posttest": "yarn run typecheck && yarn run lint", | ||
"preversion": "yarn test", | ||
"postversion": "git push && git push --tags" | ||
@@ -61,2 +62,3 @@ }, | ||
"@types/webrtc": "^0.0.21", | ||
"codecov": "^2.2.0", | ||
"dts-bundle": "^0.7.2", | ||
@@ -63,0 +65,0 @@ "jest": "^20.0.3", |
# PeerData | ||
[![Build Status](https://travis-ci.org/vardius/peer-data.svg?branch=master)](https://travis-ci.org/Vardius/peer-data) | ||
[![codecov](https://codecov.io/gh/vardius/peer-data/branch/master/graph/badge.svg)](https://codecov.io/gh/vardius/peer-data) | ||
[![npm version](https://img.shields.io/npm/v/peer-data.svg)](https://www.npmjs.com/package/peer-data) | ||
[![npm downloads](https://img.shields.io/npm/dm/peer-data.svg)](https://www.npmjs.com/package/peer-data) | ||
[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](LICENSE) | ||
@@ -34,1 +36,5 @@ PeerData is a library for bidirectional peer-to-peer transfers of arbitrary data using [RTCDataChannel](https://developer.mozilla.org/pl/docs/Web/API/RTCDataChannel). Simple *WebRTC* wrapper providing data channel abstraction. | ||
We are using the github [issue tracker](https://github.com/vardius/peer-data/issues) to manage them. | ||
## License | ||
The code is available under the [MIT license](LICENSE). |
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
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
242551
1329
40
21