From b074a4937330132e57fd62dde35aed4990db0436 Mon Sep 17 00:00:00 2001 From: Nathaniel Camomot Date: Fri, 23 Nov 2018 16:44:03 +0800 Subject: [PATCH] save --- README.md | 110 ++++-- reference/README.md | 121 ------- reference/classes/firepeer.md | 428 ------------------------ reference/interfaces/firepeeroptions.md | 83 ----- reference/interfaces/signal.md | 54 --- src/firepeer.ts | 23 +- src/test/firepeer.alice.test.ts | 2 +- src/test/firepeer.bob.test.ts | 2 +- src/test/firepeer.unauth.test.ts | 2 +- 9 files changed, 92 insertions(+), 733 deletions(-) delete mode 100644 reference/README.md delete mode 100644 reference/classes/firepeer.md delete mode 100644 reference/interfaces/firepeeroptions.md delete mode 100644 reference/interfaces/signal.md diff --git a/README.md b/README.md index 32e8358..cfd6fb6 100644 --- a/README.md +++ b/README.md @@ -6,22 +6,15 @@ secure signalling and authentication for [simple-peer](https://github.com/feross ### setup firebase -* https://firebase.google.com/docs/web/setup -* https://firebase.google.com/docs/database/web/start - -Basically, you'll need to create a firebase project and setup the JS client SDK: - -```javascript -firebase.initializeApp({ - //values from firebase console -}); -``` +Create a firebase project and setup the JS client SDK. +https://firebase.google.com/docs/web/setup +https://firebase.google.com/docs/database/web/start ### configure security rules -You need to configure your [security rules](https://firebase.google.com/docs/database/security) in the [console](https://console.firebase.google.com) like below, to secure the signalling data. What this means is only the user with uid of `$uid` can access offers sent by peers (`/peers/$uid/offers`) and only the peer who sent the offer can access the offer (`/peers/$uid/offers/$offerId`) and the corresponding answer (`/peers/$uid/offers/$offerId/answer`). This also guarantees that `/peers/$uid/offers/$offerId/uid` is the uid of the user that sent the offer. +Add these security rules in the firebase console to secure the signalling data. -```javascript +```json { "rules": { "peers": { @@ -39,40 +32,56 @@ You need to configure your [security rules](https://firebase.google.com/docs/dat } } ``` +```json +"/peers/$uid/offers": + ".read": "auth != null && auth.uid == $uid", + ".write": "auth != null && auth.uid == $uid" +``` +Ensures that offers are private to a user and can't be read or written by anyone else. Also, provides the user the ability to write an answer to an offer at `/peers/$uid/offers/$offerId/answer`. -### configure authentication method -You will also need to configure your preferred authentication method: +```json +"/peers/$uid/offers/$offerId": + ".read": "auth != null && data.child('uid').val() == auth.uid", + ".write": "auth != null && !data.exists() && newData.child('uid').val() == auth.uid" +``` +Ensures that only the user who sent the offer has read and one-time write access to that specific offer. Also guarantees that `/peers/$uid/offers/$offerId/uid` is the uid of the user who sent that offer. Crucial in authenticating the other peer. -`https://console.firebase.google.com/u/0/project//authentication/providers` +https://firebase.google.com/docs/database/security -Right now, firebase supports Email/Password, Phone, Google, Facebook, Twitter, Github, or Anonymous sign-in methods. +### enable sign-in method +By default, firebase does not enable any sign-in method. You will have to enable one in the firebase console. Right now, firebase supports Email/Password, Phone, Google, Facebook, Twitter, Github, or Anonymous sign-in methods. -More details here: -https://firebase.google.com/docs/auth/web/start +Shortcut: +`https://console.firebase.google.com/u/0/project//authentication/providers` -### install firepeer -```sh -npm install firepeer -``` - -or +https://firebase.google.com/docs/auth/web/start +### install ```html - +npm install --save firepeer + +-or- + + ``` ### use firepeer ```javascript //alice side + +firebase.initializeApp({ + //values from firebase console +}); + const alice = new FirePeer(firebase); -//authenticate -await firebase.auth().signInWith**() +//authenticate with the sign-in method you enabled in the console +await firebase.auth().signInWith*() // wait for connection -const connection = await alice.connect(); +const connection = await alice.connect(******); // send a mesage to bob connection.send('hello') @@ -80,10 +89,15 @@ connection.send('hello') ```javascript // bob side + +firebase.initializeApp({ + //values from firebase console +}); + const bob = new FirePeer(firebase); //authenticate -await firebase.auth().signInWith**() +await firebase.auth().signInWith*() // wait for connection and receive message bob.on('connection', (connection)=>{ @@ -93,12 +107,44 @@ bob.on('connection', (connection)=>{ }) ``` -> Connections are just instances of [SimplePeer](https://github.com/feross/simple-peer#api) already connected! +Connections are just instances of [SimplePeer](https://github.com/feross/simple-peer#api) already connected! + +## API +### `firepeer = new FirePeer(firebase, options?: FirePeerOptions)` +* firebase - firebase instance +* options + ```javascript + interface FirePeerOptions { + spOpts?: SimplePeer.Options; + peersPath?: string; + offersPath?: string; + answerPath?: string; + uidPath?: string; + allowOffer?: (offer: Signal) => boolean; + } + ``` + * spOpts - [SimplePeer](https://github.com/feross/simple-peer#api) constructor options. + * path parameters - + `/{peersPath}/$uid/{offersPath}/$offerId/{uidPath}` + `/{peersPath}/$uid/{offersPath}/$offerId/{answerPath}` + * allowOffer - tests whether to allow an offer to proceed + ```javascript + allowOffer: function(offer) { + return window.confirm(offer.uid + " would like to connect."); + } + ``` +### `firepeer.on('connection', (peer: SimplePeer.Instance) => void): this` +Fired when a new connection is established. +`peer` - is an instance of SimplePeer with an additional field `uid`, the uid of the other peer. + +### `firepeer.connect(uid: string): Promise` +Establish a new connection with a user identified by `uid`. +Returns a Promise that resolves a SimplePeer instance. ## Demo P2P chat made with firepeer in 100 lines of JS, more or less. :D -* https://firepeer-demo.firebaseapp.com -* https://github.com/natzcam/firepeer-demo +https://firepeer-demo.firebaseapp.com +https://github.com/natzcam/firepeer-demo diff --git a/reference/README.md b/reference/README.md deleted file mode 100644 index 5671f75..0000000 --- a/reference/README.md +++ /dev/null @@ -1,121 +0,0 @@ - -firepeer -======== - -secure signalling and authentication for [simple-peer](https://github.com/feross/simple-peer) using [firebase realtime database](https://firebase.google.com/docs/database/). - -Getting Started ---------------- - -### setup firebase - -* [https://firebase.google.com/docs/web/setup](https://firebase.google.com/docs/web/setup) -* [https://firebase.google.com/docs/database/web/start](https://firebase.google.com/docs/database/web/start) - -Basically, you'll need to create a firebase project and setup the JS client SDK: - -```javascript -firebase.initializeApp({ - //values from firebase console -}); -``` - -### configure security rules - -You need to configure your [security rules](https://firebase.google.com/docs/database/security) in the [console](https://console.firebase.google.com) like below, to secure the signalling data. What this means is only the user with uid of `$uid` can access offers sent by peers (`/peers/$uid/offers`) and only the peer who sent the offer can access the offer (`/peers/$uid/offers/$offerId`) and the corresponding answer (`/peers/$uid/offers/$offerId/answer`). This also guarantees that `/peers/$uid/offers/$offerId/uid` is the uid of the user that sent the offer. - -```javascript -{ - "rules": { - "peers": { - "$uid": { - "offers": { - ".read": "auth != null && auth.uid == $uid", - ".write": "auth != null && auth.uid == $uid", - "$offerId": { - ".read": "auth != null && data.child('uid').val() == auth.uid", - ".write": "auth != null && !data.exists() && newData.child('uid').val() == auth.uid", - } - } - } - } - } -} -``` - -### configure authentication method - -You will also need to configure your preferred authentication method: - -`https://console.firebase.google.com/u/0/project//authentication/providers` - -Right now, firebase supports Email/Password, Phone, Google, Facebook, Twitter, Github, or Anonymous sign-in methods. - -More details here: [https://firebase.google.com/docs/auth/web/start](https://firebase.google.com/docs/auth/web/start) - -### install firepeer - -```sh -npm install firepeer -``` - -or - -```html - -``` - -### use firepeer - -```javascript -//alice side -const alice = new FirePeer(firebase); - -//authenticate -await firebase.auth().signInWith**() - -// wait for connection -const connection = await alice.connect(); - -// send a mesage to bob -connection.send('hello') -``` - -```javascript -// bob side -const bob = new FirePeer(firebase); - -//authenticate -await firebase.auth().signInWith**() - -// wait for connection and receive message -bob.on('connection', (connection)=>{ - connection.on('data', (data)=>{ - console.log(data) //hello - }) -}) -``` - -> Connections are just instances of [SimplePeer](https://github.com/feross/simple-peer#api) already connected! - -Demo ----- - -P2P chat made with firepeer in 100 lines of JS, more or less. :D - -* [https://firepeer-demo.firebaseapp.com](https://firepeer-demo.firebaseapp.com) -* [https://github.com/natzcam/firepeer-demo](https://github.com/natzcam/firepeer-demo) - -## Index - -### Classes - -* [FirePeer](classes/firepeer.md) - -### Interfaces - -* [FirePeerOptions](interfaces/firepeeroptions.md) -* [Signal](interfaces/signal.md) - ---- - diff --git a/reference/classes/firepeer.md b/reference/classes/firepeer.md deleted file mode 100644 index 402b2ca..0000000 --- a/reference/classes/firepeer.md +++ /dev/null @@ -1,428 +0,0 @@ -[firepeer](../README.md) > [FirePeer](../classes/firepeer.md) - -# Class: FirePeer - -## Hierarchy - - `EventEmitter` - -**↳ FirePeer** - -## Index - -### Constructors - -* [constructor](firepeer.md#constructor) - -### Properties - -* [defaultMaxListeners](firepeer.md#defaultmaxlisteners) - -### Methods - -* [addListener](firepeer.md#addlistener) -* [connect](firepeer.md#connect) -* [emit](firepeer.md#emit) -* [eventNames](firepeer.md#eventnames) -* [getMaxListeners](firepeer.md#getmaxlisteners) -* [listenerCount](firepeer.md#listenercount) -* [listeners](firepeer.md#listeners) -* [off](firepeer.md#off) -* [on](firepeer.md#on) -* [once](firepeer.md#once) -* [prependListener](firepeer.md#prependlistener) -* [prependOnceListener](firepeer.md#prependoncelistener) -* [rawListeners](firepeer.md#rawlisteners) -* [removeAllListeners](firepeer.md#removealllisteners) -* [removeListener](firepeer.md#removelistener) -* [setMaxListeners](firepeer.md#setmaxlisteners) -* [listenerCount](firepeer.md#listenercount-1) - ---- - -## Constructors - - - -### constructor - -⊕ **new FirePeer**(fb: *`firebase`*, options?: *[FirePeerOptions](../interfaces/firepeeroptions.md)*): [FirePeer](firepeer.md) - -*Defined in [firepeer.ts:32](https://github.com/natzcam/firepeer/blob/73e993c/src/firepeer.ts#L32)* - -**Parameters:** - -| Param | Type | -| ------ | ------ | -| fb | `firebase` | -| `Optional` options | [FirePeerOptions](../interfaces/firepeeroptions.md) | - -**Returns:** [FirePeer](firepeer.md) - -___ - -## Properties - - - -### `` defaultMaxListeners - -**● defaultMaxListeners**: *`number`* - -*Inherited from EventEmitter.defaultMaxListeners* - -*Defined in C:/Users/LMPH-Cam/dev/firepeer/node_modules/@types/node/index.d.ts:1079* - -___ - -## Methods - - - -### addListener - -▸ **addListener**(event: * `string` | `symbol`*, listener: *`function`*): `this` - -*Inherited from EventEmitter.addListener* - -*Overrides EventEmitter.addListener* - -*Defined in C:/Users/LMPH-Cam/dev/firepeer/node_modules/@types/node/index.d.ts:1081* - -**Parameters:** - -| Param | Type | -| ------ | ------ | -| event | `string` | `symbol`| -| listener | `function` | - -**Returns:** `this` - -___ - - -### connect - -▸ **connect**(id: *`string`*): `Promise`<`Instance`> - -*Defined in [firepeer.ts:48](https://github.com/natzcam/firepeer/blob/73e993c/src/firepeer.ts#L48)* - -**Parameters:** - -| Param | Type | -| ------ | ------ | -| id | `string` | - -**Returns:** `Promise`<`Instance`> - -___ - - -### emit - -▸ **emit**(event: * `string` | `symbol`*, ...args: *`any`[]*): `boolean` - -*Inherited from EventEmitter.emit* - -*Overrides EventEmitter.emit* - -*Defined in C:/Users/LMPH-Cam/dev/firepeer/node_modules/@types/node/index.d.ts:1093* - -**Parameters:** - -| Param | Type | -| ------ | ------ | -| event | `string` | `symbol`| -| `Rest` args | `any`[] | - -**Returns:** `boolean` - -___ - - -### eventNames - -▸ **eventNames**(): `Array`< `string` | `symbol`> - -*Inherited from EventEmitter.eventNames* - -*Overrides EventEmitter.eventNames* - -*Defined in C:/Users/LMPH-Cam/dev/firepeer/node_modules/@types/node/index.d.ts:1094* - -**Returns:** `Array`< `string` | `symbol`> - -___ - - -### getMaxListeners - -▸ **getMaxListeners**(): `number` - -*Inherited from EventEmitter.getMaxListeners* - -*Overrides EventEmitter.getMaxListeners* - -*Defined in C:/Users/LMPH-Cam/dev/firepeer/node_modules/@types/node/index.d.ts:1090* - -**Returns:** `number` - -___ - - -### listenerCount - -▸ **listenerCount**(type: * `string` | `symbol`*): `number` - -*Inherited from EventEmitter.listenerCount* - -*Overrides EventEmitter.listenerCount* - -*Defined in C:/Users/LMPH-Cam/dev/firepeer/node_modules/@types/node/index.d.ts:1095* - -**Parameters:** - -| Param | Type | -| ------ | ------ | -| type | `string` | `symbol`| - -**Returns:** `number` - -___ - - -### listeners - -▸ **listeners**(event: * `string` | `symbol`*): `Function`[] - -*Inherited from EventEmitter.listeners* - -*Overrides EventEmitter.listeners* - -*Defined in C:/Users/LMPH-Cam/dev/firepeer/node_modules/@types/node/index.d.ts:1091* - -**Parameters:** - -| Param | Type | -| ------ | ------ | -| event | `string` | `symbol`| - -**Returns:** `Function`[] - -___ - - -### off - -▸ **off**(event: * `string` | `symbol`*, listener: *`function`*): `this` - -*Inherited from EventEmitter.off* - -*Overrides EventEmitter.off* - -*Defined in C:/Users/LMPH-Cam/dev/firepeer/node_modules/@types/node/index.d.ts:1087* - -**Parameters:** - -| Param | Type | -| ------ | ------ | -| event | `string` | `symbol`| -| listener | `function` | - -**Returns:** `this` - -___ - - -### on - -▸ **on**(event: *"connection"*, listener: *`function`*): `this` - -*Overrides EventEmitter.on* - -*Defined in [firepeer.ts:7](https://github.com/natzcam/firepeer/blob/73e993c/src/firepeer.ts#L7)* - -**Parameters:** - -| Param | Type | -| ------ | ------ | -| event | "connection" | -| listener | `function` | - -**Returns:** `this` - -___ - - -### once - -▸ **once**(event: * `string` | `symbol`*, listener: *`function`*): `this` - -*Inherited from EventEmitter.once* - -*Overrides EventEmitter.once* - -*Defined in C:/Users/LMPH-Cam/dev/firepeer/node_modules/@types/node/index.d.ts:1083* - -**Parameters:** - -| Param | Type | -| ------ | ------ | -| event | `string` | `symbol`| -| listener | `function` | - -**Returns:** `this` - -___ - - -### prependListener - -▸ **prependListener**(event: * `string` | `symbol`*, listener: *`function`*): `this` - -*Inherited from EventEmitter.prependListener* - -*Overrides EventEmitter.prependListener* - -*Defined in C:/Users/LMPH-Cam/dev/firepeer/node_modules/@types/node/index.d.ts:1084* - -**Parameters:** - -| Param | Type | -| ------ | ------ | -| event | `string` | `symbol`| -| listener | `function` | - -**Returns:** `this` - -___ - - -### prependOnceListener - -▸ **prependOnceListener**(event: * `string` | `symbol`*, listener: *`function`*): `this` - -*Inherited from EventEmitter.prependOnceListener* - -*Overrides EventEmitter.prependOnceListener* - -*Defined in C:/Users/LMPH-Cam/dev/firepeer/node_modules/@types/node/index.d.ts:1085* - -**Parameters:** - -| Param | Type | -| ------ | ------ | -| event | `string` | `symbol`| -| listener | `function` | - -**Returns:** `this` - -___ - - -### rawListeners - -▸ **rawListeners**(event: * `string` | `symbol`*): `Function`[] - -*Inherited from EventEmitter.rawListeners* - -*Overrides EventEmitter.rawListeners* - -*Defined in C:/Users/LMPH-Cam/dev/firepeer/node_modules/@types/node/index.d.ts:1092* - -**Parameters:** - -| Param | Type | -| ------ | ------ | -| event | `string` | `symbol`| - -**Returns:** `Function`[] - -___ - - -### removeAllListeners - -▸ **removeAllListeners**(event?: * `string` | `symbol`*): `this` - -*Inherited from EventEmitter.removeAllListeners* - -*Overrides EventEmitter.removeAllListeners* - -*Defined in C:/Users/LMPH-Cam/dev/firepeer/node_modules/@types/node/index.d.ts:1088* - -**Parameters:** - -| Param | Type | -| ------ | ------ | -| `Optional` event | `string` | `symbol`| - -**Returns:** `this` - -___ - - -### removeListener - -▸ **removeListener**(event: * `string` | `symbol`*, listener: *`function`*): `this` - -*Inherited from EventEmitter.removeListener* - -*Overrides EventEmitter.removeListener* - -*Defined in C:/Users/LMPH-Cam/dev/firepeer/node_modules/@types/node/index.d.ts:1086* - -**Parameters:** - -| Param | Type | -| ------ | ------ | -| event | `string` | `symbol`| -| listener | `function` | - -**Returns:** `this` - -___ - - -### setMaxListeners - -▸ **setMaxListeners**(n: *`number`*): `this` - -*Inherited from EventEmitter.setMaxListeners* - -*Overrides EventEmitter.setMaxListeners* - -*Defined in C:/Users/LMPH-Cam/dev/firepeer/node_modules/@types/node/index.d.ts:1089* - -**Parameters:** - -| Param | Type | -| ------ | ------ | -| n | `number` | - -**Returns:** `this` - -___ - - -### `` listenerCount - -▸ **listenerCount**(emitter: *`EventEmitter`*, event: * `string` | `symbol`*): `number` - -*Inherited from EventEmitter.listenerCount* - -*Defined in C:/Users/LMPH-Cam/dev/firepeer/node_modules/@types/node/index.d.ts:1078* - -*__deprecated__*: since v4.0.0 - -**Parameters:** - -| Param | Type | -| ------ | ------ | -| emitter | `EventEmitter` | -| event | `string` | `symbol`| - -**Returns:** `number` - -___ - diff --git a/reference/interfaces/firepeeroptions.md b/reference/interfaces/firepeeroptions.md deleted file mode 100644 index 23410af..0000000 --- a/reference/interfaces/firepeeroptions.md +++ /dev/null @@ -1,83 +0,0 @@ -[firepeer](../README.md) > [FirePeerOptions](../interfaces/firepeeroptions.md) - -# Interface: FirePeerOptions - -## Hierarchy - -**FirePeerOptions** - -## Index - -### Properties - -* [allowOffer](firepeeroptions.md#allowoffer) -* [answerPath](firepeeroptions.md#answerpath) -* [offersPath](firepeeroptions.md#offerspath) -* [peersPath](firepeeroptions.md#peerspath) -* [uidPath](firepeeroptions.md#uidpath) -* [wrtc](firepeeroptions.md#wrtc) - ---- - -## Properties - - - -### `` allowOffer - -**● allowOffer**: * `undefined` | `function` -* - -*Defined in [firepeer.ts:20](https://github.com/natzcam/firepeer/blob/73e993c/src/firepeer.ts#L20)* - -___ - - -### `` answerPath - -**● answerPath**: * `undefined` | `string` -* - -*Defined in [firepeer.ts:18](https://github.com/natzcam/firepeer/blob/73e993c/src/firepeer.ts#L18)* - -___ - - -### `` offersPath - -**● offersPath**: * `undefined` | `string` -* - -*Defined in [firepeer.ts:17](https://github.com/natzcam/firepeer/blob/73e993c/src/firepeer.ts#L17)* - -___ - - -### `` peersPath - -**● peersPath**: * `undefined` | `string` -* - -*Defined in [firepeer.ts:16](https://github.com/natzcam/firepeer/blob/73e993c/src/firepeer.ts#L16)* - -___ - - -### `` uidPath - -**● uidPath**: * `undefined` | `string` -* - -*Defined in [firepeer.ts:19](https://github.com/natzcam/firepeer/blob/73e993c/src/firepeer.ts#L19)* - -___ - - -### `` wrtc - -**● wrtc**: *`any`* - -*Defined in [firepeer.ts:15](https://github.com/natzcam/firepeer/blob/73e993c/src/firepeer.ts#L15)* - -___ - diff --git a/reference/interfaces/signal.md b/reference/interfaces/signal.md deleted file mode 100644 index 4a848b1..0000000 --- a/reference/interfaces/signal.md +++ /dev/null @@ -1,54 +0,0 @@ -[firepeer](../README.md) > [Signal](../interfaces/signal.md) - -# Interface: Signal - -## Hierarchy - - `SignalData` - -**↳ Signal** - -## Index - -### Properties - -* [candidate](signal.md#candidate) -* [sdp](signal.md#sdp) -* [uid](signal.md#uid) - ---- - -## Properties - - - -### `` candidate - -**● candidate**: *`any`* - -*Inherited from SignalData.candidate* - -*Defined in C:/Users/LMPH-Cam/dev/firepeer/node_modules/@types/simple-peer/index.d.ts:44* - -___ - - -### `` sdp - -**● sdp**: *`any`* - -*Inherited from SignalData.sdp* - -*Defined in C:/Users/LMPH-Cam/dev/firepeer/node_modules/@types/simple-peer/index.d.ts:43* - -___ - - -### uid - -**● uid**: *`string`* - -*Defined in [firepeer.ts:11](https://github.com/natzcam/firepeer/blob/73e993c/src/firepeer.ts#L11)* - -___ - diff --git a/src/firepeer.ts b/src/firepeer.ts index 8050f24..81e58ba 100644 --- a/src/firepeer.ts +++ b/src/firepeer.ts @@ -12,25 +12,23 @@ export interface Signal extends SimplePeer.SignalData { } export interface FirePeerOptions { - wrtc?: any; + spOpts?: SimplePeer.Options; peersPath?: string; offersPath?: string; answerPath?: string; uidPath?: string; - allowOffer?: (offer: Signal) => any; + allowOffer?: (offer: Signal) => boolean; } export class FirePeer extends EventEmitter { private ref?: firebase.database.Reference; private refSub: any; - private wrtc?: any; + private spOpts: SimplePeer.Options = { trickle: false }; private user: firebase.User | null | undefined; private peersPath = 'peers'; private offersPath = 'offers'; private answerPath = 'answer'; private uidPath = 'uid'; - private allowOffer: (offer: Signal) => boolean = (offer: Signal) => true; - constructor(private fb: typeof firebase, options?: FirePeerOptions) { super(); Object.assign(this, options); @@ -45,20 +43,20 @@ export class FirePeer extends EventEmitter { }); } - public connect(id: string): Promise { + public connect(uid: string): Promise { const offersRef = this.fb .database() - .ref(`${this.peersPath}/${id}/${this.offersPath}`); + .ref(`${this.peersPath}/${uid}/${this.offersPath}`); debug('connect() %s', offersRef.toString()); return new Promise((resolve, reject) => { const peer = new SimplePeer({ initiator: true, - trickle: false, - wrtc: this.wrtc + ...this.spOpts, + trickle: false }); - (peer as any).uid = id; + (peer as any).uid = uid; peer.on('signal', (offer: any) => { if (this.user) { @@ -107,6 +105,7 @@ export class FirePeer extends EventEmitter { }); }); } + private allowOffer: (offer: Signal) => boolean = (offer: Signal) => true; private listen(user: firebase.User): void { this.ref = this.fb @@ -138,8 +137,8 @@ export class FirePeer extends EventEmitter { private incoming(ref: firebase.database.Reference, offer: Signal): void { const peer = new SimplePeer({ initiator: false, - trickle: false, - wrtc: this.wrtc + ...this.spOpts, + trickle: false }); (peer as any).uid = offer.uid; diff --git a/src/test/firepeer.alice.test.ts b/src/test/firepeer.alice.test.ts index 8d6df18..fe215c7 100644 --- a/src/test/firepeer.alice.test.ts +++ b/src/test/firepeer.alice.test.ts @@ -21,7 +21,7 @@ test.after(async t => { }); test.serial('alice tries to connect to bob authenticated', async t => { - const alice = new FirePeer(firebase, { wrtc }); + const alice = new FirePeer(firebase, { spOpts: { wrtc } }); await alice.connect(process.env.BOB_UID as string); t.pass(); }); diff --git a/src/test/firepeer.bob.test.ts b/src/test/firepeer.bob.test.ts index 348a7e2..49177bb 100644 --- a/src/test/firepeer.bob.test.ts +++ b/src/test/firepeer.bob.test.ts @@ -19,7 +19,7 @@ test.after(async t => { }); test.serial('bob waits for connection from alice authenticated', async t => { - const bob = new FirePeer(firebase, { wrtc }); + const bob = new FirePeer(firebase, { spOpts: { wrtc } }); await waitConn(bob); t.pass(); }); diff --git a/src/test/firepeer.unauth.test.ts b/src/test/firepeer.unauth.test.ts index 73cb379..10319d7 100644 --- a/src/test/firepeer.unauth.test.ts +++ b/src/test/firepeer.unauth.test.ts @@ -6,6 +6,6 @@ import { FirePeer } from '../firepeer'; import firebase from './firebase.fixture'; test.serial('alice tries to connect to bob unauthenticated', async t => { - const alice = new FirePeer(firebase, { wrtc }); + const alice = new FirePeer(firebase, { spOpts: { wrtc } }); await t.throwsAsync(alice.connect(process.env.BOB_UID as string)); });