Skip to content

Commit 15ece8e

Browse files
committed
feat: polyfill WebRTC in Node
1 parent 5175cc3 commit 15ece8e

File tree

5 files changed

+28
-6
lines changed

5 files changed

+28
-6
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Peer extends Lite {
2828
/**
2929
* Add a Transceiver to the connection.
3030
* @param {String} kind
31-
* @param {Object} init
31+
* @param {Object=} init
3232
*/
3333
addTransceiver (kind, init) {
3434
if (this._destroying) return

package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@thaunknown/simple-peer",
33
"description": "Simple one-to-one WebRTC video/voice and data channels",
4-
"version": "9.12.1",
4+
"version": "10.0.0",
55
"type": "module",
66
"author": {
77
"name": "ThaUnknown",
@@ -18,8 +18,10 @@
1818
"debug": "^4.3.4",
1919
"err-code": "^3.0.1",
2020
"streamx": "^2.16.1",
21-
"uint8-util": "^2.1.9",
22-
"webrtc-polyfill": "^1.0.12"
21+
"uint8-util": "^2.1.9"
22+
},
23+
"optionalDependencies": {
24+
"webrtc-polyfill": "^1.0.14"
2325
},
2426
"devDependencies": {
2527
"@babel/core": "^7.20.12",
@@ -28,6 +30,7 @@
2830
"airtap-manual": "^1.0.0",
2931
"babelify": "^10.0.0",
3032
"bowser": "^2.11.0",
33+
"cross-env": "^7.0.3",
3134
"prettier-bytes": "^1.0.4",
3235
"speedometer": "^1.1.0",
3336
"string-to-stream": "^3.0.1",
@@ -59,7 +62,8 @@
5962
"scripts": {
6063
"test": "npm run test-node && npm run test-browser",
6164
"test-browser-local": "airtap --preset local -- test/*.js",
62-
"test-node": "tape test/*.js"
65+
"test-node": "tape test/*.js",
66+
"test-node-debug": "cross-env DEBUG=* tape test/negotiation.js"
6367
},
6468
"contributors": [
6569
{

test/basic.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import common from './common.js'
22
import Peer from '../index.js'
33
import test from 'tape'
44

5+
process.on('uncaughtException', console.error) // User-Initiated Abort, reason=Close called
6+
57
test('detect WebRTC support', function (t) {
68
t.equal(Peer.WEBRTC_SUPPORT, true, 'builtin webrtc support')
79
t.end()
@@ -239,7 +241,7 @@ test('ensure iceStateChange fires when connection failed', (t) => {
239241
t.plan(1)
240242
const peer = new Peer({ initiator: true })
241243

242-
peer.on('iceStateChange', (connectionState, gatheringState) => {
244+
peer.once('iceStateChange', (connectionState, gatheringState) => {
243245
t.pass('got iceStateChange')
244246
t.end()
245247
})

test/multistream.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Peer from '../index.js'
33
import test from 'tape'
44

55
test('multistream', function (t) {
6+
if (!process.browser) return t.end()
67
if (common.isBrowser('ios')) {
78
t.pass('Skip on iOS emulator which does not support this reliably') // iOS emulator issue #486
89
t.end()
@@ -47,6 +48,7 @@ test('multistream', function (t) {
4748
})
4849

4950
test('multistream (track event)', function (t) {
51+
if (!process.browser) return t.end()
5052
t.plan(20)
5153

5254
const peer1 = new Peer({
@@ -88,6 +90,7 @@ test('multistream (track event)', function (t) {
8890
})
8991

9092
test('multistream on non-initiator only', function (t) {
93+
if (!process.browser) return t.end()
9194
t.plan(30)
9295

9396
const peer1 = new Peer({
@@ -126,6 +129,7 @@ test('multistream on non-initiator only', function (t) {
126129
})
127130

128131
test('delayed stream on non-initiator', function (t) {
132+
if (!process.browser) return t.end()
129133
if (common.isBrowser('ios')) {
130134
t.pass('Skip on iOS which does not support this reliably')
131135
t.end()
@@ -162,6 +166,7 @@ test('delayed stream on non-initiator', function (t) {
162166
})
163167

164168
test('incremental multistream', function (t) {
169+
if (!process.browser) return t.end()
165170
if (common.isBrowser('ios')) {
166171
t.pass('Skip on iOS emulator which does not support this reliably') // iOS emulator issue #486
167172
t.end()
@@ -226,6 +231,7 @@ test('incremental multistream', function (t) {
226231
})
227232

228233
test('incremental multistream (track event)', function (t) {
234+
if (!process.browser) return t.end()
229235
t.plan(22)
230236

231237
const peer1 = new Peer({
@@ -285,6 +291,7 @@ test('incremental multistream (track event)', function (t) {
285291
})
286292

287293
test('incremental multistream on non-initiator only', function (t) {
294+
if (!process.browser) return t.end()
288295
if (common.isBrowser('ios')) {
289296
t.pass('Skip on iOS emulator which does not support this reliably') // iOS emulator issue #486
290297
t.end()
@@ -334,6 +341,7 @@ test('incremental multistream on non-initiator only', function (t) {
334341
})
335342

336343
test('incremental multistream on non-initiator only (track event)', function (t) {
344+
if (!process.browser) return t.end()
337345
t.plan(12)
338346

339347
const peer1 = new Peer({
@@ -378,6 +386,7 @@ test('incremental multistream on non-initiator only (track event)', function (t)
378386
})
379387

380388
test('addStream after removeStream', function (t) {
389+
if (!process.browser) return t.end()
381390
if (common.isBrowser('ios')) {
382391
t.pass('Skip on iOS which does not support this reliably')
383392
t.end()
@@ -412,6 +421,7 @@ test('addStream after removeStream', function (t) {
412421
})
413422

414423
test('removeTrack immediately', function (t) {
424+
if (!process.browser) return t.end()
415425
t.plan(2)
416426

417427
const peer1 = new Peer({ initiator: true })
@@ -450,6 +460,7 @@ test('removeTrack immediately', function (t) {
450460
})
451461

452462
test('replaceTrack', function (t) {
463+
if (!process.browser) return t.end()
453464
t.plan(4)
454465

455466
const peer1 = new Peer({ initiator: true })

test/negotiation.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Peer from '../index.js'
33
import test from 'tape'
44

55
test('single negotiation', function (t) {
6+
if (!process.browser) return t.end()
67
t.plan(10)
78

89
const peer1 = new Peer({ initiator: true, stream: common.getMediaStream() })
@@ -50,6 +51,7 @@ test('single negotiation', function (t) {
5051
})
5152

5253
test('manual renegotiation', function (t) {
54+
if (!process.browser) return t.end()
5355
t.plan(2)
5456

5557
const peer1 = new Peer({ initiator: true })
@@ -71,6 +73,7 @@ test('manual renegotiation', function (t) {
7173
})
7274

7375
test('repeated manual renegotiation', function (t) {
76+
if (!process.browser) return t.end()
7477
t.plan(6)
7578

7679
const peer1 = new Peer({ initiator: true })
@@ -107,6 +110,7 @@ test('repeated manual renegotiation', function (t) {
107110
})
108111

109112
test('renegotiation after addStream', function (t) {
113+
if (!process.browser) return t.end()
110114
if (common.isBrowser('ios')) {
111115
t.pass('Skip on iOS which does not support this reliably')
112116
t.end()
@@ -137,6 +141,7 @@ test('renegotiation after addStream', function (t) {
137141
})
138142

139143
test('add stream on non-initiator only', function (t) {
144+
if (!process.browser) return t.end()
140145
t.plan(3)
141146

142147
const peer1 = new Peer({

0 commit comments

Comments
 (0)