peer-data
Advanced tools
Comparing version 1.2.26 to 2.0.0
@@ -1,4 +0,4 @@ | ||
// Generated by dts-bundle v0.7.2 | ||
// Generated by dts-bundle v0.7.3 | ||
export { EventDispatcher, AppEventType, PeerCollection, DataChannelCollection, Signaling, SignalingEvent, SignalingEventType, SocketChannel }; | ||
export { EventDispatcher, AppEventType, Signaling, SignalingEvent, SignalingEventType, SocketChannel }; | ||
export default PeerData; | ||
@@ -9,7 +9,10 @@ | ||
on(event: string, callback: EventHandler): void; | ||
send(data: any, id?: string): void; | ||
connect(roomId?: string): void; | ||
disconnect(roomId?: string): void; | ||
peers(id?: string): PeerCollection | RTCPeerConnection; | ||
channels(id?: string): DataChannelCollection | RTCDataChannel; | ||
onConnection(callback: EventHandler): void; | ||
onLog(callback: EventHandler): void; | ||
connect(roomId: string): void; | ||
disconnect(roomId: string): void; | ||
_onRoom(event: SignalingEvent): void; | ||
_onOffer(mainEvent: SignalingEvent): void; | ||
_onConnect(mainEvent: SignalingEvent): void; | ||
_onDisconnect(event: SignalingEvent): void; | ||
} | ||
@@ -20,2 +23,3 @@ | ||
static register(type: any, callback: EventHandler): void; | ||
static unregister(type: any, callback: EventHandler): void; | ||
static dispatch(type: any, data?: any): void; | ||
@@ -26,15 +30,5 @@ } | ||
static LOG: string; | ||
static ERROR: string; | ||
static PEER: string; | ||
static CHANNEL: string; | ||
static CONNECTION: string; | ||
} | ||
export interface PeerCollection { | ||
[index: string]: RTCPeerConnection; | ||
} | ||
export interface DataChannelCollection { | ||
[index: string]: RTCDataChannel; | ||
} | ||
export interface Signaling { | ||
@@ -59,2 +53,3 @@ onSend(message: SignalingEvent): void; | ||
static ERROR: string; | ||
static ROOM: string; | ||
} | ||
@@ -70,3 +65,3 @@ | ||
export interface EventHandlerCollection { | ||
[index: string]: EventHandler[]; | ||
[type: string]: EventHandler[]; | ||
} | ||
@@ -73,0 +68,0 @@ |
@@ -1,13 +0,17 @@ | ||
import { EventHandler } from './dispatcher/handler'; | ||
import { PeerCollection } from './peer/collection'; | ||
import { DataChannelCollection } from './channel/collection'; | ||
import { SignalingEvent } from './SignalingEvent'; | ||
import { EventHandler } from './EventHandler'; | ||
export declare class App { | ||
private bridge; | ||
private servers; | ||
private dataConstraints; | ||
private connection; | ||
constructor(servers?: RTCConfiguration, dataConstraints?: RTCDataChannelInit); | ||
on(event: string, callback: EventHandler): void; | ||
send(data: any, id?: string): void; | ||
connect(roomId?: string): void; | ||
disconnect(roomId?: string): void; | ||
peers(id?: string): PeerCollection | RTCPeerConnection; | ||
channels(id?: string): DataChannelCollection | RTCDataChannel; | ||
onConnection(callback: EventHandler): void; | ||
onLog(callback: EventHandler): void; | ||
connect(roomId: string): void; | ||
disconnect(roomId: string): void; | ||
_onRoom(event: SignalingEvent): void; | ||
_onOffer(mainEvent: SignalingEvent): void; | ||
_onConnect(mainEvent: SignalingEvent): void; | ||
_onDisconnect(event: SignalingEvent): void; | ||
} |
@@ -1,5 +0,7 @@ | ||
import { EventDispatcher } from './dispatcher/dispatcher'; | ||
import { SignalingEventType } from './signaling/event-type'; | ||
import { Connection } from './connection/connection'; | ||
import { Bridge } from './bridge'; | ||
import { EventDispatcher } from './EventDispatcher'; | ||
import { SignalingEventType } from './SignalingEventType'; | ||
import { Connection } from './Connection'; | ||
import { PeerFactory } from './PeerFactory'; | ||
import { DataChannelFactory } from './DataChannelFactory'; | ||
import { AppEventType } from './AppEventType'; | ||
var App = (function () { | ||
@@ -9,4 +11,13 @@ function App(servers, dataConstraints) { | ||
if (dataConstraints === void 0) { dataConstraints = null; } | ||
var connection = new Connection(servers, dataConstraints); | ||
this.bridge = new Bridge(connection); | ||
this.servers = servers; | ||
this.dataConstraints = dataConstraints; | ||
this.connection = new Connection(); | ||
// We already have this peer return it | ||
EventDispatcher.register(SignalingEventType.ROOM, this._onRoom.bind(this)); | ||
// We got connection offer create answer and establish connection | ||
EventDispatcher.register(SignalingEventType.OFFER, this._onOffer.bind(this)); | ||
// Someone wants to connect create offer | ||
EventDispatcher.register(SignalingEventType.CONNECT, this._onConnect.bind(this)); | ||
// Tell others we disconnected | ||
EventDispatcher.register(SignalingEventType.DISCONNECT, this._onDisconnect.bind(this)); | ||
} | ||
@@ -16,22 +27,10 @@ App.prototype.on = function (event, callback) { | ||
}; | ||
App.prototype.send = function (data, id) { | ||
if (id) { | ||
var channel = this.bridge.connection.channels[id]; | ||
if (channel && channel.readyState === 'open') { | ||
channel.send(data); | ||
} | ||
} | ||
else { | ||
Object | ||
.entries(this.bridge.connection.channels) | ||
.forEach(function (_a) { | ||
var key = _a[0], value = _a[1]; | ||
if (value.readyState === 'open') { | ||
value.send(data); | ||
} | ||
}); | ||
} | ||
App.prototype.onConnection = function (callback) { | ||
EventDispatcher.register(AppEventType.CONNECTION, callback); | ||
}; | ||
App.prototype.onLog = function (callback) { | ||
EventDispatcher.register(AppEventType.LOG, callback); | ||
}; | ||
App.prototype.connect = function (roomId) { | ||
var event = { | ||
EventDispatcher.dispatch('send', { | ||
type: SignalingEventType.CONNECT, | ||
@@ -42,20 +41,6 @@ caller: null, | ||
data: null, | ||
}; | ||
EventDispatcher.dispatch('send', event); | ||
}); | ||
}; | ||
App.prototype.disconnect = function (roomId) { | ||
var connection = this.bridge.connection; | ||
Object | ||
.entries(connection.channels) | ||
.forEach(function (_a) { | ||
var key = _a[0], value = _a[1]; | ||
return connection.removeChannel(key); | ||
}); | ||
Object | ||
.entries(connection.peers) | ||
.forEach(function (_a) { | ||
var key = _a[0], value = _a[1]; | ||
return connection.removePeer(key); | ||
}); | ||
var event = { | ||
EventDispatcher.dispatch('send', { | ||
type: SignalingEventType.DISCONNECT, | ||
@@ -66,16 +51,139 @@ caller: null, | ||
data: null, | ||
}; | ||
EventDispatcher.dispatch('send', event); | ||
}); | ||
this.connection.removeRoom(roomId); | ||
}; | ||
App.prototype.peers = function (id) { | ||
if (id) { | ||
return this.bridge.connection.peers[id]; | ||
} | ||
return this.bridge.connection.peers; | ||
App.prototype._onRoom = function (event) { | ||
var _this = this; | ||
var promise = new Promise(function (resolve, reject) { | ||
var peer = _this.connection.getPeer(event.caller.id); | ||
var channel = _this.connection.getChannel(event.caller.id); | ||
if (null !== peer && null !== channel) { | ||
resolve({ room: event.room, caller: event.caller, peer: peer, channel: channel }); | ||
} | ||
else { | ||
reject('Invalid peer or data channel.'); | ||
} | ||
}); | ||
EventDispatcher.dispatch(AppEventType.CONNECTION, promise); | ||
}; | ||
App.prototype.channels = function (id) { | ||
if (id) { | ||
return this.bridge.connection.channels[id]; | ||
App.prototype._onOffer = function (mainEvent) { | ||
var _this = this; | ||
var promise = new Promise(function (resolve, reject) { | ||
var channel; | ||
var peer = PeerFactory.get(_this.servers, mainEvent); | ||
_this.connection.addPeer(mainEvent.caller.id, peer); | ||
var onCandidate = function (event) { | ||
if (event.caller.id !== mainEvent.caller.id) { | ||
return; | ||
} | ||
peer | ||
.addIceCandidate(new RTCIceCandidate(event.data)) | ||
.catch(function (evnt) { return reject(evnt); }); | ||
}; | ||
var onDataChannel = function (event) { | ||
_this.connection.addChannel(mainEvent.caller.id, event.channel); | ||
if (peer.connectionState === 'connected') { | ||
resolve({ room: mainEvent.room, caller: mainEvent.caller, peer: peer, channel: channel }); | ||
} | ||
else { | ||
channel = event.channel; | ||
} | ||
}; | ||
var onConnectionStateChange = function (event) { | ||
if (peer.connectionState === 'connected' && channel) { | ||
resolve({ room: mainEvent.room, caller: mainEvent.caller, peer: peer, channel: channel }); | ||
} | ||
}; | ||
peer.ondatachannel = onDataChannel; | ||
peer.onconnectionstatechange = onConnectionStateChange; | ||
peer | ||
.setRemoteDescription(new RTCSessionDescription(mainEvent.data)) | ||
.then(function () { return peer.createAnswer(); }) | ||
.then(function (desc) { return peer.setLocalDescription(desc); }) | ||
.then(function () { return EventDispatcher.dispatch('send', { | ||
type: SignalingEventType.ANSWER, | ||
caller: null, | ||
callee: mainEvent.caller, | ||
room: mainEvent.room, | ||
data: peer.localDescription, | ||
}); }) | ||
.catch(function (evnt) { return reject(evnt); }); | ||
var handlerMap = new Map(); | ||
handlerMap.set(SignalingEventType.CANDIDATE, onCandidate); | ||
_this.connection.handlers.set(mainEvent.caller.id, handlerMap); | ||
EventDispatcher.register(SignalingEventType.CANDIDATE, onCandidate); | ||
}); | ||
EventDispatcher.dispatch(AppEventType.CONNECTION, promise); | ||
}; | ||
App.prototype._onConnect = function (mainEvent) { | ||
var _this = this; | ||
var promise = new Promise(function (resolve, reject) { | ||
var peer = _this.connection.getPeer(mainEvent.caller.id); | ||
var channel = _this.connection.getChannel(mainEvent.caller.id); | ||
if (null !== peer && null !== channel) { | ||
EventDispatcher.dispatch('send', { | ||
type: SignalingEventType.ROOM, | ||
caller: null, | ||
callee: mainEvent.caller, | ||
room: mainEvent.room, | ||
data: null, | ||
}); | ||
resolve({ room: mainEvent.room, caller: mainEvent.caller, peer: peer, channel: channel }); | ||
} | ||
else { | ||
peer = PeerFactory.get(_this.servers, mainEvent); | ||
channel = DataChannelFactory.get(peer, _this.dataConstraints); | ||
_this.connection.addChannel(mainEvent.caller.id, channel); | ||
_this.connection.addPeer(mainEvent.caller.id, peer); | ||
var onConnectionStateChange = function (event) { | ||
if (peer.connectionState === 'connected') { | ||
resolve({ room: mainEvent.room, caller: mainEvent.caller, peer: peer, channel: channel }); | ||
} | ||
}; | ||
var onCandidate = function (event) { | ||
if (mainEvent.caller.id !== event.caller.id) { | ||
return; | ||
} | ||
peer | ||
.addIceCandidate(new RTCIceCandidate(event.data)) | ||
.catch(function (evnt) { return reject(evnt); }); | ||
}; | ||
var onAnswer = function (event) { | ||
if (mainEvent.caller.id !== event.caller.id) { | ||
return; | ||
} | ||
peer | ||
.setRemoteDescription(new RTCSessionDescription(event.data)) | ||
.catch(function (evnt) { return reject(evnt); }); | ||
}; | ||
peer.onconnectionstatechange = onConnectionStateChange; | ||
peer | ||
.createOffer() | ||
.then(function (desc) { return peer.setLocalDescription(desc); }) | ||
.then(function () { return EventDispatcher.dispatch('send', { | ||
type: SignalingEventType.OFFER, | ||
caller: null, | ||
callee: mainEvent.caller, | ||
room: mainEvent.room, | ||
data: peer.localDescription, | ||
}); }) | ||
.catch(function (evnt) { return reject(evnt); }); | ||
var handlerMap = new Map(); | ||
handlerMap.set(SignalingEventType.ANSWER, onAnswer); | ||
handlerMap.set(SignalingEventType.CANDIDATE, onCandidate); | ||
_this.connection.handlers.set(mainEvent.caller.id, handlerMap); | ||
EventDispatcher.register(SignalingEventType.ANSWER, onAnswer); | ||
EventDispatcher.register(SignalingEventType.CANDIDATE, onCandidate); | ||
} | ||
}); | ||
EventDispatcher.dispatch(AppEventType.CONNECTION, promise); | ||
}; | ||
App.prototype._onDisconnect = function (event) { | ||
if (!event.room) { | ||
this.connection.removeChannel(event.caller.id); | ||
this.connection.removePeer(event.caller.id); | ||
} | ||
return this.bridge.connection.channels; | ||
else { | ||
// todo: close peer if this room was our only connection | ||
} | ||
}; | ||
@@ -82,0 +190,0 @@ return App; |
import { App as PeerData } from './app/app'; | ||
import { EventDispatcher } from './app/dispatcher/dispatcher'; | ||
import { AppEventType } from './app/event-type'; | ||
import { PeerCollection } from './app/peer/collection'; | ||
import { DataChannelCollection } from './app/channel/collection'; | ||
import { Signaling } from './app/signaling/signaling'; | ||
import { SignalingEvent } from './app/signaling/event'; | ||
import { SignalingEventType } from './app/signaling/event-type'; | ||
import { SocketChannel } from './app/signaling/socket-channel'; | ||
export { EventDispatcher, AppEventType, PeerCollection, DataChannelCollection, Signaling, SignalingEvent, SignalingEventType, SocketChannel }; | ||
import { EventDispatcher } from './app/EventDispatcher'; | ||
import { AppEventType } from './app/AppEventType'; | ||
import { Signaling } from './app/Signaling'; | ||
import { SignalingEvent } from './app/SignalingEvent'; | ||
import { SignalingEventType } from './app/SignalingEventType'; | ||
import { SocketChannel } from './app/SocketChannel'; | ||
export { EventDispatcher, AppEventType, Signaling, SignalingEvent, SignalingEventType, SocketChannel }; | ||
export default PeerData; |
import { App as PeerData } from './app/app'; | ||
import { EventDispatcher } from './app/dispatcher/dispatcher'; | ||
import { AppEventType } from './app/event-type'; | ||
import { SignalingEventType } from './app/signaling/event-type'; | ||
import { SocketChannel } from './app/signaling/socket-channel'; | ||
import { EventDispatcher } from './app/EventDispatcher'; | ||
import { AppEventType } from './app/AppEventType'; | ||
import { SignalingEventType } from './app/SignalingEventType'; | ||
import { SocketChannel } from './app/SocketChannel'; | ||
export { EventDispatcher, AppEventType, SignalingEventType, SocketChannel, }; | ||
export default PeerData; | ||
//# sourceMappingURL=index.js.map |
@@ -1,13 +0,17 @@ | ||
import { EventHandler } from './dispatcher/handler'; | ||
import { PeerCollection } from './peer/collection'; | ||
import { DataChannelCollection } from './channel/collection'; | ||
import { SignalingEvent } from './SignalingEvent'; | ||
import { EventHandler } from './EventHandler'; | ||
export declare class App { | ||
private bridge; | ||
private servers; | ||
private dataConstraints; | ||
private connection; | ||
constructor(servers?: RTCConfiguration, dataConstraints?: RTCDataChannelInit); | ||
on(event: string, callback: EventHandler): void; | ||
send(data: any, id?: string): void; | ||
connect(roomId?: string): void; | ||
disconnect(roomId?: string): void; | ||
peers(id?: string): PeerCollection | RTCPeerConnection; | ||
channels(id?: string): DataChannelCollection | RTCDataChannel; | ||
onConnection(callback: EventHandler): void; | ||
onLog(callback: EventHandler): void; | ||
connect(roomId: string): void; | ||
disconnect(roomId: string): void; | ||
_onRoom(event: SignalingEvent): void; | ||
_onOffer(mainEvent: SignalingEvent): void; | ||
_onConnect(mainEvent: SignalingEvent): void; | ||
_onDisconnect(event: SignalingEvent): void; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var dispatcher_1 = require("./dispatcher/dispatcher"); | ||
var event_type_1 = require("./signaling/event-type"); | ||
var connection_1 = require("./connection/connection"); | ||
var bridge_1 = require("./bridge"); | ||
var EventDispatcher_1 = require("./EventDispatcher"); | ||
var SignalingEventType_1 = require("./SignalingEventType"); | ||
var Connection_1 = require("./Connection"); | ||
var PeerFactory_1 = require("./PeerFactory"); | ||
var DataChannelFactory_1 = require("./DataChannelFactory"); | ||
var AppEventType_1 = require("./AppEventType"); | ||
var App = (function () { | ||
@@ -11,29 +13,26 @@ function App(servers, dataConstraints) { | ||
if (dataConstraints === void 0) { dataConstraints = null; } | ||
var connection = new connection_1.Connection(servers, dataConstraints); | ||
this.bridge = new bridge_1.Bridge(connection); | ||
this.servers = servers; | ||
this.dataConstraints = dataConstraints; | ||
this.connection = new Connection_1.Connection(); | ||
// We already have this peer return it | ||
EventDispatcher_1.EventDispatcher.register(SignalingEventType_1.SignalingEventType.ROOM, this._onRoom.bind(this)); | ||
// We got connection offer create answer and establish connection | ||
EventDispatcher_1.EventDispatcher.register(SignalingEventType_1.SignalingEventType.OFFER, this._onOffer.bind(this)); | ||
// Someone wants to connect create offer | ||
EventDispatcher_1.EventDispatcher.register(SignalingEventType_1.SignalingEventType.CONNECT, this._onConnect.bind(this)); | ||
// Tell others we disconnected | ||
EventDispatcher_1.EventDispatcher.register(SignalingEventType_1.SignalingEventType.DISCONNECT, this._onDisconnect.bind(this)); | ||
} | ||
App.prototype.on = function (event, callback) { | ||
dispatcher_1.EventDispatcher.register(event, callback); | ||
EventDispatcher_1.EventDispatcher.register(event, callback); | ||
}; | ||
App.prototype.send = function (data, id) { | ||
if (id) { | ||
var channel = this.bridge.connection.channels[id]; | ||
if (channel && channel.readyState === 'open') { | ||
channel.send(data); | ||
} | ||
} | ||
else { | ||
Object | ||
.entries(this.bridge.connection.channels) | ||
.forEach(function (_a) { | ||
var key = _a[0], value = _a[1]; | ||
if (value.readyState === 'open') { | ||
value.send(data); | ||
} | ||
}); | ||
} | ||
App.prototype.onConnection = function (callback) { | ||
EventDispatcher_1.EventDispatcher.register(AppEventType_1.AppEventType.CONNECTION, callback); | ||
}; | ||
App.prototype.onLog = function (callback) { | ||
EventDispatcher_1.EventDispatcher.register(AppEventType_1.AppEventType.LOG, callback); | ||
}; | ||
App.prototype.connect = function (roomId) { | ||
var event = { | ||
type: event_type_1.SignalingEventType.CONNECT, | ||
EventDispatcher_1.EventDispatcher.dispatch('send', { | ||
type: SignalingEventType_1.SignalingEventType.CONNECT, | ||
caller: null, | ||
@@ -43,21 +42,7 @@ callee: null, | ||
data: null, | ||
}; | ||
dispatcher_1.EventDispatcher.dispatch('send', event); | ||
}); | ||
}; | ||
App.prototype.disconnect = function (roomId) { | ||
var connection = this.bridge.connection; | ||
Object | ||
.entries(connection.channels) | ||
.forEach(function (_a) { | ||
var key = _a[0], value = _a[1]; | ||
return connection.removeChannel(key); | ||
}); | ||
Object | ||
.entries(connection.peers) | ||
.forEach(function (_a) { | ||
var key = _a[0], value = _a[1]; | ||
return connection.removePeer(key); | ||
}); | ||
var event = { | ||
type: event_type_1.SignalingEventType.DISCONNECT, | ||
EventDispatcher_1.EventDispatcher.dispatch('send', { | ||
type: SignalingEventType_1.SignalingEventType.DISCONNECT, | ||
caller: null, | ||
@@ -67,16 +52,139 @@ callee: null, | ||
data: null, | ||
}; | ||
dispatcher_1.EventDispatcher.dispatch('send', event); | ||
}); | ||
this.connection.removeRoom(roomId); | ||
}; | ||
App.prototype.peers = function (id) { | ||
if (id) { | ||
return this.bridge.connection.peers[id]; | ||
} | ||
return this.bridge.connection.peers; | ||
App.prototype._onRoom = function (event) { | ||
var _this = this; | ||
var promise = new Promise(function (resolve, reject) { | ||
var peer = _this.connection.getPeer(event.caller.id); | ||
var channel = _this.connection.getChannel(event.caller.id); | ||
if (null !== peer && null !== channel) { | ||
resolve({ room: event.room, caller: event.caller, peer: peer, channel: channel }); | ||
} | ||
else { | ||
reject('Invalid peer or data channel.'); | ||
} | ||
}); | ||
EventDispatcher_1.EventDispatcher.dispatch(AppEventType_1.AppEventType.CONNECTION, promise); | ||
}; | ||
App.prototype.channels = function (id) { | ||
if (id) { | ||
return this.bridge.connection.channels[id]; | ||
App.prototype._onOffer = function (mainEvent) { | ||
var _this = this; | ||
var promise = new Promise(function (resolve, reject) { | ||
var channel; | ||
var peer = PeerFactory_1.PeerFactory.get(_this.servers, mainEvent); | ||
_this.connection.addPeer(mainEvent.caller.id, peer); | ||
var onCandidate = function (event) { | ||
if (event.caller.id !== mainEvent.caller.id) { | ||
return; | ||
} | ||
peer | ||
.addIceCandidate(new RTCIceCandidate(event.data)) | ||
.catch(function (evnt) { return reject(evnt); }); | ||
}; | ||
var onDataChannel = function (event) { | ||
_this.connection.addChannel(mainEvent.caller.id, event.channel); | ||
if (peer.connectionState === 'connected') { | ||
resolve({ room: mainEvent.room, caller: mainEvent.caller, peer: peer, channel: channel }); | ||
} | ||
else { | ||
channel = event.channel; | ||
} | ||
}; | ||
var onConnectionStateChange = function (event) { | ||
if (peer.connectionState === 'connected' && channel) { | ||
resolve({ room: mainEvent.room, caller: mainEvent.caller, peer: peer, channel: channel }); | ||
} | ||
}; | ||
peer.ondatachannel = onDataChannel; | ||
peer.onconnectionstatechange = onConnectionStateChange; | ||
peer | ||
.setRemoteDescription(new RTCSessionDescription(mainEvent.data)) | ||
.then(function () { return peer.createAnswer(); }) | ||
.then(function (desc) { return peer.setLocalDescription(desc); }) | ||
.then(function () { return EventDispatcher_1.EventDispatcher.dispatch('send', { | ||
type: SignalingEventType_1.SignalingEventType.ANSWER, | ||
caller: null, | ||
callee: mainEvent.caller, | ||
room: mainEvent.room, | ||
data: peer.localDescription, | ||
}); }) | ||
.catch(function (evnt) { return reject(evnt); }); | ||
var handlerMap = new Map(); | ||
handlerMap.set(SignalingEventType_1.SignalingEventType.CANDIDATE, onCandidate); | ||
_this.connection.handlers.set(mainEvent.caller.id, handlerMap); | ||
EventDispatcher_1.EventDispatcher.register(SignalingEventType_1.SignalingEventType.CANDIDATE, onCandidate); | ||
}); | ||
EventDispatcher_1.EventDispatcher.dispatch(AppEventType_1.AppEventType.CONNECTION, promise); | ||
}; | ||
App.prototype._onConnect = function (mainEvent) { | ||
var _this = this; | ||
var promise = new Promise(function (resolve, reject) { | ||
var peer = _this.connection.getPeer(mainEvent.caller.id); | ||
var channel = _this.connection.getChannel(mainEvent.caller.id); | ||
if (null !== peer && null !== channel) { | ||
EventDispatcher_1.EventDispatcher.dispatch('send', { | ||
type: SignalingEventType_1.SignalingEventType.ROOM, | ||
caller: null, | ||
callee: mainEvent.caller, | ||
room: mainEvent.room, | ||
data: null, | ||
}); | ||
resolve({ room: mainEvent.room, caller: mainEvent.caller, peer: peer, channel: channel }); | ||
} | ||
else { | ||
peer = PeerFactory_1.PeerFactory.get(_this.servers, mainEvent); | ||
channel = DataChannelFactory_1.DataChannelFactory.get(peer, _this.dataConstraints); | ||
_this.connection.addChannel(mainEvent.caller.id, channel); | ||
_this.connection.addPeer(mainEvent.caller.id, peer); | ||
var onConnectionStateChange = function (event) { | ||
if (peer.connectionState === 'connected') { | ||
resolve({ room: mainEvent.room, caller: mainEvent.caller, peer: peer, channel: channel }); | ||
} | ||
}; | ||
var onCandidate = function (event) { | ||
if (mainEvent.caller.id !== event.caller.id) { | ||
return; | ||
} | ||
peer | ||
.addIceCandidate(new RTCIceCandidate(event.data)) | ||
.catch(function (evnt) { return reject(evnt); }); | ||
}; | ||
var onAnswer = function (event) { | ||
if (mainEvent.caller.id !== event.caller.id) { | ||
return; | ||
} | ||
peer | ||
.setRemoteDescription(new RTCSessionDescription(event.data)) | ||
.catch(function (evnt) { return reject(evnt); }); | ||
}; | ||
peer.onconnectionstatechange = onConnectionStateChange; | ||
peer | ||
.createOffer() | ||
.then(function (desc) { return peer.setLocalDescription(desc); }) | ||
.then(function () { return EventDispatcher_1.EventDispatcher.dispatch('send', { | ||
type: SignalingEventType_1.SignalingEventType.OFFER, | ||
caller: null, | ||
callee: mainEvent.caller, | ||
room: mainEvent.room, | ||
data: peer.localDescription, | ||
}); }) | ||
.catch(function (evnt) { return reject(evnt); }); | ||
var handlerMap = new Map(); | ||
handlerMap.set(SignalingEventType_1.SignalingEventType.ANSWER, onAnswer); | ||
handlerMap.set(SignalingEventType_1.SignalingEventType.CANDIDATE, onCandidate); | ||
_this.connection.handlers.set(mainEvent.caller.id, handlerMap); | ||
EventDispatcher_1.EventDispatcher.register(SignalingEventType_1.SignalingEventType.ANSWER, onAnswer); | ||
EventDispatcher_1.EventDispatcher.register(SignalingEventType_1.SignalingEventType.CANDIDATE, onCandidate); | ||
} | ||
}); | ||
EventDispatcher_1.EventDispatcher.dispatch(AppEventType_1.AppEventType.CONNECTION, promise); | ||
}; | ||
App.prototype._onDisconnect = function (event) { | ||
if (!event.room) { | ||
this.connection.removeChannel(event.caller.id); | ||
this.connection.removePeer(event.caller.id); | ||
} | ||
return this.bridge.connection.channels; | ||
else { | ||
// todo: close peer if this room was our only connection | ||
} | ||
}; | ||
@@ -83,0 +191,0 @@ return App; |
import { App as PeerData } from './app/app'; | ||
import { EventDispatcher } from './app/dispatcher/dispatcher'; | ||
import { AppEventType } from './app/event-type'; | ||
import { PeerCollection } from './app/peer/collection'; | ||
import { DataChannelCollection } from './app/channel/collection'; | ||
import { Signaling } from './app/signaling/signaling'; | ||
import { SignalingEvent } from './app/signaling/event'; | ||
import { SignalingEventType } from './app/signaling/event-type'; | ||
import { SocketChannel } from './app/signaling/socket-channel'; | ||
export { EventDispatcher, AppEventType, PeerCollection, DataChannelCollection, Signaling, SignalingEvent, SignalingEventType, SocketChannel }; | ||
import { EventDispatcher } from './app/EventDispatcher'; | ||
import { AppEventType } from './app/AppEventType'; | ||
import { Signaling } from './app/Signaling'; | ||
import { SignalingEvent } from './app/SignalingEvent'; | ||
import { SignalingEventType } from './app/SignalingEventType'; | ||
import { SocketChannel } from './app/SocketChannel'; | ||
export { EventDispatcher, AppEventType, Signaling, SignalingEvent, SignalingEventType, SocketChannel }; | ||
export default PeerData; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var app_1 = require("./app/app"); | ||
var dispatcher_1 = require("./app/dispatcher/dispatcher"); | ||
exports.EventDispatcher = dispatcher_1.EventDispatcher; | ||
var event_type_1 = require("./app/event-type"); | ||
exports.AppEventType = event_type_1.AppEventType; | ||
var event_type_2 = require("./app/signaling/event-type"); | ||
exports.SignalingEventType = event_type_2.SignalingEventType; | ||
var socket_channel_1 = require("./app/signaling/socket-channel"); | ||
exports.SocketChannel = socket_channel_1.SocketChannel; | ||
var EventDispatcher_1 = require("./app/EventDispatcher"); | ||
exports.EventDispatcher = EventDispatcher_1.EventDispatcher; | ||
var AppEventType_1 = require("./app/AppEventType"); | ||
exports.AppEventType = AppEventType_1.AppEventType; | ||
var SignalingEventType_1 = require("./app/SignalingEventType"); | ||
exports.SignalingEventType = SignalingEventType_1.SignalingEventType; | ||
var SocketChannel_1 = require("./app/SocketChannel"); | ||
exports.SocketChannel = SocketChannel_1.SocketChannel; | ||
exports.default = app_1.App; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "peer-data", | ||
"version": "1.2.26", | ||
"version": "2.0.0", | ||
"description": "PeerData - library for files, media streaming/sharing using WebRTC", | ||
@@ -61,4 +61,4 @@ "scripts": { | ||
"devDependencies": { | ||
"@types/jest": "^19.2.4", | ||
"@types/node": "^7.0.31", | ||
"@types/jest": "^20.0.2", | ||
"@types/node": "^8.0.2", | ||
"@types/socket.io-client": "^1.4.29", | ||
@@ -68,3 +68,3 @@ "@types/webrtc": "^0.0.21", | ||
"cross-env": "^5.0.1", | ||
"dts-bundle": "^0.7.2", | ||
"dts-bundle": "^0.7.3", | ||
"jest": "^20.0.4", | ||
@@ -90,4 +90,4 @@ "jest-cli": "^20.0.4", | ||
"socket.io-client": "^2.0.3", | ||
"webrtc-adapter": "^4.0.1" | ||
"webrtc-adapter": "^4.0.2" | ||
} | ||
} |
Sorry, the diff of this file is too big to display
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
431794
1449
102
1
Updatedwebrtc-adapter@^4.0.2