From 36d9665163b40fba6cd983fa7c12346ffe448c23 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Wed, 28 Oct 2020 19:02:07 -1000 Subject: [PATCH] standard --- index.js | 68 +++++++++++++++++----------------- perf/receive.js | 14 +++---- perf/send.js | 14 +++---- perf/server.js | 6 +-- test/basic.js | 46 +++++++++++------------ test/binary.js | 20 +++++----- test/common.js | 8 ++-- test/multistream.js | 90 ++++++++++++++++++++++----------------------- test/negotiation.js | 36 +++++++++--------- test/object-mode.js | 24 ++++++------ test/stream.js | 18 ++++----- test/trickle.js | 48 ++++++++++++------------ test/z-cleanup.js | 2 +- 13 files changed, 197 insertions(+), 197 deletions(-) diff --git a/index.js b/index.js index a571166f..21afa09a 100644 --- a/index.js +++ b/index.js @@ -1,14 +1,14 @@ /*! simple-peer. MIT License. Feross Aboukhadijeh */ -var debug = require('debug')('simple-peer') -var getBrowserRTC = require('get-browser-rtc') -var randombytes = require('randombytes') -var stream = require('readable-stream') -var queueMicrotask = require('queue-microtask') // TODO: remove when Node 10 is not supported -var errCode = require('err-code') +const debug = require('debug')('simple-peer') +const getBrowserRTC = require('get-browser-rtc') +const randombytes = require('randombytes') +const stream = require('readable-stream') +const queueMicrotask = require('queue-microtask') // TODO: remove when Node 10 is not supported +const errCode = require('err-code') -var MAX_BUFFERED_AMOUNT = 64 * 1024 -var ICECOMPLETE_TIMEOUT = 5 * 1000 -var CHANNEL_CLOSING_TIMEOUT = 5 * 1000 +const MAX_BUFFERED_AMOUNT = 64 * 1024 +const ICECOMPLETE_TIMEOUT = 5 * 1000 +const CHANNEL_CLOSING_TIMEOUT = 5 * 1000 // HACK: Filter trickle lines when trickle is disabled #354 function filterTrickle (sdp) { @@ -218,7 +218,7 @@ class Peer extends stream.Duplex { } _addIceCandidate (candidate) { - var iceCandidateObj = new this._wrtc.RTCIceCandidate(candidate) + const iceCandidateObj = new this._wrtc.RTCIceCandidate(candidate) this._pc.addIceCandidate(iceCandidateObj) .catch(err => { if (!iceCandidateObj.address || iceCandidateObj.address.endsWith('.local')) { @@ -279,8 +279,8 @@ class Peer extends stream.Duplex { addTrack (track, stream) { this._debug('addTrack()') - var submap = this._senderMap.get(track) || new Map() // nested Maps map [track, stream] to sender - var sender = submap.get(stream) + const submap = this._senderMap.get(track) || new Map() // nested Maps map [track, stream] to sender + let sender = submap.get(stream) if (!sender) { sender = this._pc.addTrack(track, stream) submap.set(stream, sender) @@ -302,8 +302,8 @@ class Peer extends stream.Duplex { replaceTrack (oldTrack, newTrack, stream) { this._debug('replaceTrack()') - var submap = this._senderMap.get(oldTrack) - var sender = submap ? submap.get(stream) : null + const submap = this._senderMap.get(oldTrack) + const sender = submap ? submap.get(stream) : null if (!sender) { throw errCode(new Error('Cannot replace track that was never added.'), 'ERR_TRACK_NOT_ADDED') } @@ -324,8 +324,8 @@ class Peer extends stream.Duplex { removeTrack (track, stream) { this._debug('removeSender()') - var submap = this._senderMap.get(track) - var sender = submap ? submap.get(stream) : null + const submap = this._senderMap.get(track) + const sender = submap ? submap.get(stream) : null if (!sender) { throw errCode(new Error('Cannot remove track that was never added.'), 'ERR_TRACK_NOT_ADDED') } @@ -496,7 +496,7 @@ class Peer extends stream.Duplex { // HACK: Chrome will sometimes get stuck in readyState "closing", let's check for this condition // https://bugs.chromium.org/p/chromium/issues/detail?id=882743 - var isClosing = false + let isClosing = false this._closingInterval = setInterval(() => { // No "onclosing" event if (this._channel && this._channel.readyState === 'closing') { if (isClosing) this._onChannelClose() // closing timed out: equivalent to onclose firing @@ -574,7 +574,7 @@ class Peer extends stream.Duplex { const sendOffer = () => { if (this.destroyed) return - var signal = this._pc.localDescription || offer + const signal = this._pc.localDescription || offer this._debug('signal') this.emit('signal', { type: signal.type, @@ -624,7 +624,7 @@ class Peer extends stream.Duplex { const sendAnswer = () => { if (this.destroyed) return - var signal = this._pc.localDescription || answer + const signal = this._pc.localDescription || answer this._debug('signal') this.emit('signal', { type: signal.type, @@ -661,8 +661,8 @@ class Peer extends stream.Duplex { _onIceStateChange () { if (this.destroyed) return - var iceConnectionState = this._pc.iceConnectionState - var iceGatheringState = this._pc.iceGatheringState + const iceConnectionState = this._pc.iceConnectionState + const iceGatheringState = this._pc.iceGatheringState this._debug( 'iceStateChange (connection: %s) (gathering: %s)', @@ -698,7 +698,7 @@ class Peer extends stream.Duplex { if (this._pc.getStats.length === 0 || this._isReactNativeWebrtc) { this._pc.getStats() .then(res => { - var reports = [] + const reports = [] res.forEach(report => { reports.push(flattenValues(report)) }) @@ -711,9 +711,9 @@ class Peer extends stream.Duplex { // If we destroy connection in `connect` callback this code might happen to run when actual connection is already closed if (this.destroyed) return - var reports = [] + const reports = [] res.result().forEach(result => { - var report = {} + const report = {} result.names().forEach(name => { report[name] = result.stat(name) }) @@ -748,10 +748,10 @@ class Peer extends stream.Duplex { // Treat getStats error as non-fatal. It's not essential. if (err) items = [] - var remoteCandidates = {} - var localCandidates = {} - var candidatePairs = {} - var foundSelectedCandidatePair = false + const remoteCandidates = {} + const localCandidates = {} + const candidatePairs = {} + let foundSelectedCandidatePair = false items.forEach(item => { // TODO: Once all browsers support the hyphenated stats report types, remove @@ -770,7 +770,7 @@ class Peer extends stream.Duplex { const setSelectedCandidatePair = selectedCandidatePair => { foundSelectedCandidatePair = true - var local = localCandidates[selectedCandidatePair.localCandidateId] + let local = localCandidates[selectedCandidatePair.localCandidateId] if (local && (local.ip || local.address)) { // Spec @@ -790,7 +790,7 @@ class Peer extends stream.Duplex { this.localFamily = this.localAddress.includes(':') ? 'IPv6' : 'IPv4' } - var remote = remoteCandidates[selectedCandidatePair.remoteCandidateId] + let remote = remoteCandidates[selectedCandidatePair.remoteCandidateId] if (remote && (remote.ip || remote.address)) { // Spec @@ -853,7 +853,7 @@ class Peer extends stream.Duplex { this._chunk = null this._debug('sent chunk from "write before connect"') - var cb = this._cb + const cb = this._cb this._cb = null cb(null) } @@ -929,7 +929,7 @@ class Peer extends stream.Duplex { _onChannelMessage (event) { if (this.destroyed) return - var data = event.data + let data = event.data if (data instanceof ArrayBuffer) data = Buffer.from(data) this.push(data) } @@ -937,7 +937,7 @@ class Peer extends stream.Duplex { _onChannelBufferedAmountLow () { if (this.destroyed || !this._cb) return this._debug('ending backpressure: bufferedAmount %d', this._channel.bufferedAmount) - var cb = this._cb + const cb = this._cb this._cb = null cb(null) } @@ -979,7 +979,7 @@ class Peer extends stream.Duplex { } _debug () { - var args = [].slice.call(arguments) + const args = [].slice.call(arguments) args[0] = '[' + this._id + '] ' + args[0] debug.apply(null, args) } diff --git a/perf/receive.js b/perf/receive.js index ae21fc53..f7b3d199 100644 --- a/perf/receive.js +++ b/perf/receive.js @@ -3,20 +3,20 @@ // 7.6MB -var prettierBytes = require('prettier-bytes') -var speedometer = require('speedometer') -var Peer = require('simple-peer') +const prettierBytes = require('prettier-bytes') +const speedometer = require('speedometer') +const Peer = require('simple-peer') -var speed = speedometer() +const speed = speedometer() -var peer +let peer -var socket = new window.WebSocket('ws://localhost:8080') +const socket = new window.WebSocket('ws://localhost:8080') socket.addEventListener('message', onMessage) function onMessage (event) { - var message = event.data + const message = event.data if (message === 'ready') { if (peer) return peer = new Peer() diff --git a/perf/send.js b/perf/send.js index 9b43f383..cd02449d 100644 --- a/perf/send.js +++ b/perf/send.js @@ -1,25 +1,25 @@ // run in a browser, with: // beefy perf/send.js -var Peer = require('simple-peer') -var stream = require('readable-stream') +const Peer = require('simple-peer') +const stream = require('readable-stream') -var buf = Buffer.alloc(10000) +const buf = Buffer.alloc(10000) -var endless = new stream.Readable({ +const endless = new stream.Readable({ read: function () { this.push(buf) } }) -var peer +let peer -var socket = new window.WebSocket('ws://localhost:8080') +const socket = new window.WebSocket('ws://localhost:8080') socket.addEventListener('message', onMessage) function onMessage (event) { - var message = event.data + const message = event.data if (message === 'ready') { if (peer) return peer = new Peer({ initiator: true }) diff --git a/perf/server.js b/perf/server.js index f6a736f7..fb8545fa 100644 --- a/perf/server.js +++ b/perf/server.js @@ -1,12 +1,12 @@ // run in a terminal, to do signaling for peers -var ws = require('ws') +const ws = require('ws') -var server = new ws.Server({ +const server = new ws.Server({ port: 8080 }) -var sockets = [] +const sockets = [] server.on('connection', function (socket) { sockets.push(socket) diff --git a/test/basic.js b/test/basic.js index 7a6fcc18..886598dd 100644 --- a/test/basic.js +++ b/test/basic.js @@ -1,8 +1,8 @@ -var common = require('./common') -var Peer = require('../') -var test = require('tape') +const common = require('./common') +const Peer = require('../') +const test = require('tape') -var config +let config test('get config', function (t) { common.getConfig(function (err, _config) { if (err) return t.fail(err) @@ -20,7 +20,7 @@ test('create peer without options', function (t) { t.plan(1) if (process.browser) { - var peer + let peer t.doesNotThrow(function () { peer = new Peer() }) @@ -33,7 +33,7 @@ test('create peer without options', function (t) { test('can detect error when RTCPeerConstructor throws', function (t) { t.plan(1) - var peer = new Peer({ wrtc: { RTCPeerConnection: null } }) + const peer = new Peer({ wrtc: { RTCPeerConnection: null } }) peer.once('error', function () { t.pass('got error event') peer.destroy() @@ -43,7 +43,7 @@ test('can detect error when RTCPeerConstructor throws', function (t) { test('signal event gets emitted', function (t) { t.plan(2) - var peer = new Peer({ config, initiator: true, wrtc: common.wrtc }) + const peer = new Peer({ config, initiator: true, wrtc: common.wrtc }) peer.once('signal', function () { t.pass('got signal event') peer.on('close', function () { t.pass('peer destroyed') }) @@ -52,7 +52,7 @@ test('signal event gets emitted', function (t) { }) test('signal event does not get emitted by non-initiator', function (t) { - var peer = new Peer({ config, initiator: false, wrtc: common.wrtc }) + const peer = new Peer({ config, initiator: false, wrtc: common.wrtc }) peer.once('signal', function () { t.fail('got signal event') peer.on('close', function () { t.pass('peer destroyed') }) @@ -66,7 +66,7 @@ test('signal event does not get emitted by non-initiator', function (t) { }) test('signal event does not get emitted by non-initiator with stream', function (t) { - var peer = new Peer({ + const peer = new Peer({ config, stream: common.getMediaStream(), initiator: false, @@ -87,16 +87,16 @@ test('signal event does not get emitted by non-initiator with stream', function test('data send/receive text', function (t) { t.plan(10) - var peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc }) - var peer2 = new Peer({ config, wrtc: common.wrtc }) + const peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc }) + const peer2 = new Peer({ config, wrtc: common.wrtc }) - var numSignal1 = 0 + let numSignal1 = 0 peer1.on('signal', function (data) { numSignal1 += 1 peer2.signal(data) }) - var numSignal2 = 0 + let numSignal2 = 0 peer2.on('signal', function (data) { numSignal2 += 1 peer1.signal(data) @@ -135,8 +135,8 @@ test('data send/receive text', function (t) { test('sdpTransform function is called', function (t) { t.plan(3) - var peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc }) - var peer2 = new Peer({ config, sdpTransform, wrtc: common.wrtc }) + const peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc }) + const peer2 = new Peer({ config, sdpTransform, wrtc: common.wrtc }) function sdpTransform (sdp) { t.equal(typeof sdp, 'string', 'got a string as SDP') @@ -161,15 +161,15 @@ test('sdpTransform function is called', function (t) { test('old constraint formats are used', function (t) { t.plan(3) - var constraints = { + const constraints = { mandatory: { OfferToReceiveAudio: true, OfferToReceiveVideo: true } } - var peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc, constraints }) - var peer2 = new Peer({ config, wrtc: common.wrtc, constraints }) + const peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc, constraints }) + const peer2 = new Peer({ config, wrtc: common.wrtc, constraints }) peer1.on('signal', function (data) { peer2.signal(data) @@ -191,13 +191,13 @@ test('old constraint formats are used', function (t) { test('new constraint formats are used', function (t) { t.plan(3) - var constraints = { + const constraints = { offerToReceiveAudio: true, offerToReceiveVideo: true } - var peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc, constraints }) - var peer2 = new Peer({ config, wrtc: common.wrtc, constraints }) + const peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc, constraints }) + const peer2 = new Peer({ config, wrtc: common.wrtc, constraints }) peer1.on('signal', function (data) { peer2.signal(data) @@ -230,8 +230,8 @@ test('ensure remote address and port are available right after connection', func t.plan(7) - var peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc }) - var peer2 = new Peer({ config, wrtc: common.wrtc }) + const peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc }) + const peer2 = new Peer({ config, wrtc: common.wrtc }) peer1.on('signal', function (data) { peer2.signal(data) diff --git a/test/binary.js b/test/binary.js index 186d37df..80f07614 100644 --- a/test/binary.js +++ b/test/binary.js @@ -1,8 +1,8 @@ -var common = require('./common') -var Peer = require('../') -var test = require('tape') +const common = require('./common') +const Peer = require('../') +const test = require('tape') -var config +let config test('get config', function (t) { common.getConfig(function (err, _config) { if (err) return t.fail(err) @@ -14,8 +14,8 @@ test('get config', function (t) { test('data send/receive Buffer', function (t) { t.plan(6) - var peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc }) - var peer2 = new Peer({ config, wrtc: common.wrtc }) + const peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc }) + const peer2 = new Peer({ config, wrtc: common.wrtc }) peer1.on('signal', function (data) { peer2.signal(data) }) @@ -50,8 +50,8 @@ test('data send/receive Buffer', function (t) { test('data send/receive Uint8Array', function (t) { t.plan(6) - var peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc }) - var peer2 = new Peer({ config, wrtc: common.wrtc }) + const peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc }) + const peer2 = new Peer({ config, wrtc: common.wrtc }) peer1.on('signal', function (data) { peer2.signal(data) }) @@ -88,8 +88,8 @@ test('data send/receive Uint8Array', function (t) { test('data send/receive ArrayBuffer', function (t) { t.plan(6) - var peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc }) - var peer2 = new Peer({ config, wrtc: common.wrtc }) + const peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc }) + const peer2 = new Peer({ config, wrtc: common.wrtc }) peer1.on('signal', function (data) { peer2.signal(data) }) diff --git a/test/common.js b/test/common.js index bf402078..204c3024 100644 --- a/test/common.js +++ b/test/common.js @@ -1,6 +1,6 @@ -var get = require('simple-get') -var thunky = require('thunky') -var bowser = require('bowser') +const get = require('simple-get') +const thunky = require('thunky') +const bowser = require('bowser') exports.getConfig = thunky(function (cb) { // Includes TURN -- needed for tests to pass on Sauce Labs @@ -25,7 +25,7 @@ if (process.env.WRTC === 'wrtc') { } // create a test MediaStream with two tracks -var canvas +let canvas exports.getMediaStream = function () { if (exports.wrtc) { const source = new exports.wrtc.nonstandard.RTCVideoSource() diff --git a/test/multistream.js b/test/multistream.js index e8ab5eec..d29e0d3d 100644 --- a/test/multistream.js +++ b/test/multistream.js @@ -1,8 +1,8 @@ -var common = require('./common') -var Peer = require('../') -var test = require('tape') +const common = require('./common') +const Peer = require('../') +const test = require('tape') -var config +let config test('get config', function (t) { common.getConfig(function (err, _config) { if (err) return t.fail(err) @@ -19,13 +19,13 @@ test('multistream', function (t) { } t.plan(20) - var peer1 = new Peer({ + const peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc, streams: (new Array(10)).fill(null).map(function () { return common.getMediaStream() }) }) - var peer2 = new Peer({ + const peer2 = new Peer({ config, wrtc: common.wrtc, streams: (new Array(10)).fill(null).map(function () { return common.getMediaStream() }) @@ -34,7 +34,7 @@ test('multistream', function (t) { peer1.on('signal', function (data) { if (!peer2.destroyed) peer2.signal(data) }) peer2.on('signal', function (data) { if (!peer1.destroyed) peer1.signal(data) }) - var receivedIds = {} + const receivedIds = {} peer1.on('stream', function (stream) { t.pass('peer1 got stream') @@ -62,13 +62,13 @@ test('multistream', function (t) { test('multistream (track event)', function (t) { t.plan(20) - var peer1 = new Peer({ + const peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc, streams: (new Array(5)).fill(null).map(function () { return common.getMediaStream() }) }) - var peer2 = new Peer({ + const peer2 = new Peer({ config, wrtc: common.wrtc, streams: (new Array(5)).fill(null).map(function () { return common.getMediaStream() }) @@ -77,7 +77,7 @@ test('multistream (track event)', function (t) { peer1.on('signal', function (data) { if (!peer2.destroyed) peer2.signal(data) }) peer2.on('signal', function (data) { if (!peer1.destroyed) peer1.signal(data) }) - var receivedIds = {} + const receivedIds = {} peer1.on('track', function (track) { t.pass('peer1 got track') @@ -105,13 +105,13 @@ test('multistream (track event)', function (t) { test('multistream on non-initiator only', function (t) { t.plan(30) - var peer1 = new Peer({ + const peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc, streams: [] }) - var peer2 = new Peer({ + const peer2 = new Peer({ config, wrtc: common.wrtc, streams: (new Array(10)).fill(null).map(function () { return common.getMediaStream() }) @@ -126,7 +126,7 @@ test('multistream on non-initiator only', function (t) { if (!peer1.destroyed) peer1.signal(data) }) - var receivedIds = {} + const receivedIds = {} peer1.on('stream', function (stream) { t.pass('peer1 got stream') @@ -152,14 +152,14 @@ test('delayed stream on non-initiator', function (t) { t.timeoutAfter(15000) t.plan(1) - var peer1 = new Peer({ + const peer1 = new Peer({ config, trickle: true, initiator: true, wrtc: common.wrtc, streams: [common.getMediaStream()] }) - var peer2 = new Peer({ + const peer2 = new Peer({ config, trickle: true, wrtc: common.wrtc, @@ -190,13 +190,13 @@ test('incremental multistream', function (t) { } t.plan(12) - var peer1 = new Peer({ + const peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc, streams: [] }) - var peer2 = new Peer({ + const peer2 = new Peer({ config, wrtc: common.wrtc, streams: [] @@ -214,9 +214,9 @@ test('incremental multistream', function (t) { peer2.addStream(common.getMediaStream()) }) - var receivedIds = {} + const receivedIds = {} - var count1 = 0 + let count1 = 0 peer1.on('stream', function (stream) { t.pass('peer1 got stream') if (receivedIds[stream.id]) { @@ -230,7 +230,7 @@ test('incremental multistream', function (t) { } }) - var count2 = 0 + let count2 = 0 peer2.on('stream', function (stream) { t.pass('peer2 got stream') if (receivedIds[stream.id]) { @@ -253,13 +253,13 @@ test('incremental multistream', function (t) { test('incremental multistream (track event)', function (t) { t.plan(22) - var peer1 = new Peer({ + const peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc, streams: [] }) - var peer2 = new Peer({ + const peer2 = new Peer({ config, wrtc: common.wrtc, streams: [] @@ -277,9 +277,9 @@ test('incremental multistream (track event)', function (t) { peer2.addStream(common.getMediaStream()) }) - var receivedIds = {} + const receivedIds = {} - var count1 = 0 + let count1 = 0 peer1.on('track', function (track) { t.pass('peer1 got track') if (receivedIds[track.id]) { @@ -293,7 +293,7 @@ test('incremental multistream (track event)', function (t) { } }) - var count2 = 0 + let count2 = 0 peer2.on('track', function (track) { t.pass('peer2 got track') if (receivedIds[track.id]) { @@ -321,13 +321,13 @@ test('incremental multistream on non-initiator only', function (t) { } t.plan(7) - var peer1 = new Peer({ + const peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc, streams: [] }) - var peer2 = new Peer({ + const peer2 = new Peer({ config, wrtc: common.wrtc, streams: [] @@ -344,9 +344,9 @@ test('incremental multistream on non-initiator only', function (t) { peer2.addStream(common.getMediaStream()) }) - var receivedIds = {} + const receivedIds = {} - var count = 0 + let count = 0 peer1.on('stream', function (stream) { t.pass('peer1 got stream') if (receivedIds[stream.id]) { @@ -369,13 +369,13 @@ test('incremental multistream on non-initiator only', function (t) { test('incremental multistream on non-initiator only (track event)', function (t) { t.plan(12) - var peer1 = new Peer({ + const peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc, streams: [] }) - var peer2 = new Peer({ + const peer2 = new Peer({ config, wrtc: common.wrtc, streams: [] @@ -392,9 +392,9 @@ test('incremental multistream on non-initiator only (track event)', function (t) peer2.addStream(common.getMediaStream()) }) - var receivedIds = {} + const receivedIds = {} - var count = 0 + let count = 0 peer1.on('track', function (track) { t.pass('peer1 got track') if (receivedIds[track.id]) { @@ -422,11 +422,11 @@ test('addStream after removeStream', function (t) { } t.plan(2) - var stream1 = common.getMediaStream() - var stream2 = common.getMediaStream() + const stream1 = common.getMediaStream() + const stream2 = common.getMediaStream() - var peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc }) - var peer2 = new Peer({ config, wrtc: common.wrtc, streams: [stream1] }) + const peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc }) + const peer2 = new Peer({ config, wrtc: common.wrtc, streams: [stream1] }) peer1.on('signal', function (data) { if (!peer2.destroyed) peer2.signal(data) }) peer2.on('signal', function (data) { if (!peer1.destroyed) peer1.signal(data) }) @@ -451,14 +451,14 @@ test('addStream after removeStream', function (t) { test('removeTrack immediately', function (t) { t.plan(2) - var peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc }) - var peer2 = new Peer({ config, wrtc: common.wrtc }) + const peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc }) + const peer2 = new Peer({ config, wrtc: common.wrtc }) peer1.on('signal', function (data) { if (!peer2.destroyed) peer2.signal(data) }) peer2.on('signal', function (data) { if (!peer1.destroyed) peer1.signal(data) }) - var stream1 = common.getMediaStream() - var stream2 = common.getMediaStream() + const stream1 = common.getMediaStream() + const stream2 = common.getMediaStream() peer1.addTrack(stream1.getTracks()[0], stream1) peer2.addTrack(stream2.getTracks()[0], stream2) @@ -489,14 +489,14 @@ test('removeTrack immediately', function (t) { test('replaceTrack', function (t) { t.plan(4) - var peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc }) - var peer2 = new Peer({ config, wrtc: common.wrtc }) + const peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc }) + const peer2 = new Peer({ config, wrtc: common.wrtc }) peer1.on('signal', function (data) { if (!peer2.destroyed) peer2.signal(data) }) peer2.on('signal', function (data) { if (!peer1.destroyed) peer1.signal(data) }) - var stream1 = common.getMediaStream() - var stream2 = common.getMediaStream() + const stream1 = common.getMediaStream() + const stream2 = common.getMediaStream() peer1.addTrack(stream1.getTracks()[0], stream1) peer2.addTrack(stream2.getTracks()[0], stream2) diff --git a/test/negotiation.js b/test/negotiation.js index 234a3c0a..5ae4c539 100644 --- a/test/negotiation.js +++ b/test/negotiation.js @@ -1,8 +1,8 @@ -var common = require('./common') -var Peer = require('../') -var test = require('tape') +const common = require('./common') +const Peer = require('../') +const test = require('tape') -var config +let config test('get config', function (t) { common.getConfig(function (err, _config) { if (err) return t.fail(err) @@ -14,8 +14,8 @@ test('get config', function (t) { test('single negotiation', function (t) { t.plan(10) - var peer1 = new Peer({ config, initiator: true, stream: common.getMediaStream(), wrtc: common.wrtc }) - var peer2 = new Peer({ config, stream: common.getMediaStream(), wrtc: common.wrtc }) + const peer1 = new Peer({ config, initiator: true, stream: common.getMediaStream(), wrtc: common.wrtc }) + const peer2 = new Peer({ config, stream: common.getMediaStream(), wrtc: common.wrtc }) peer1.on('signal', function (data) { if (data.renegotiate) t.fail('got unexpected request to renegotiate') @@ -40,7 +40,7 @@ test('single negotiation', function (t) { t.pass('peer2 got stream') }) - var trackCount1 = 0 + let trackCount1 = 0 peer1.on('track', function (track) { t.pass('peer1 got track') trackCount1++ @@ -48,7 +48,7 @@ test('single negotiation', function (t) { t.pass('got correct number of tracks') } }) - var trackCount2 = 0 + let trackCount2 = 0 peer2.on('track', function (track) { t.pass('peer2 got track') trackCount2++ @@ -61,8 +61,8 @@ test('single negotiation', function (t) { test('manual renegotiation', function (t) { t.plan(2) - var peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc }) - var peer2 = new Peer({ config, wrtc: common.wrtc }) + const peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc }) + const peer2 = new Peer({ config, wrtc: common.wrtc }) peer1.on('signal', function (data) { if (!peer2.destroyed) peer2.signal(data) }) peer2.on('signal', function (data) { if (!peer1.destroyed) peer1.signal(data) }) @@ -82,8 +82,8 @@ test('manual renegotiation', function (t) { test('repeated manual renegotiation', function (t) { t.plan(6) - var peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc }) - var peer2 = new Peer({ config, wrtc: common.wrtc }) + const peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc }) + const peer2 = new Peer({ config, wrtc: common.wrtc }) peer1.on('signal', function (data) { if (!peer2.destroyed) peer2.signal(data) }) peer2.on('signal', function (data) { if (!peer1.destroyed) peer1.signal(data) }) @@ -123,8 +123,8 @@ test('renegotiation after addStream', function (t) { } t.plan(4) - var peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc }) - var peer2 = new Peer({ config, wrtc: common.wrtc }) + const peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc }) + const peer2 = new Peer({ config, wrtc: common.wrtc }) peer1.on('signal', function (data) { if (!peer2.destroyed) peer2.signal(data) }) peer2.on('signal', function (data) { if (!peer1.destroyed) peer1.signal(data) }) @@ -148,12 +148,12 @@ test('renegotiation after addStream', function (t) { test('add stream on non-initiator only', function (t) { t.plan(3) - var peer1 = new Peer({ + const peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc }) - var peer2 = new Peer({ + const peer2 = new Peer({ config, wrtc: common.wrtc, stream: common.getMediaStream() @@ -176,7 +176,7 @@ test('add stream on non-initiator only', function (t) { test('negotiated channels', function (t) { t.plan(2) - var peer1 = new Peer({ + const peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc, @@ -185,7 +185,7 @@ test('negotiated channels', function (t) { negotiated: true } }) - var peer2 = new Peer({ + const peer2 = new Peer({ config, wrtc: common.wrtc, channelConfig: { diff --git a/test/object-mode.js b/test/object-mode.js index c7b5e642..17230178 100644 --- a/test/object-mode.js +++ b/test/object-mode.js @@ -1,8 +1,8 @@ -var common = require('./common') -var Peer = require('../') -var test = require('tape') +const common = require('./common') +const Peer = require('../') +const test = require('tape') -var config +let config test('get config', function (t) { common.getConfig(function (err, _config) { if (err) return t.fail(err) @@ -14,8 +14,8 @@ test('get config', function (t) { test('data send/receive string {objectMode: true}', function (t) { t.plan(6) - var peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc, objectMode: true }) - var peer2 = new Peer({ config, wrtc: common.wrtc, objectMode: true }) + const peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc, objectMode: true }) + const peer2 = new Peer({ config, wrtc: common.wrtc, objectMode: true }) peer1.on('signal', function (data) { peer2.signal(data) }) @@ -50,8 +50,8 @@ test('data send/receive string {objectMode: true}', function (t) { test('data send/receive Buffer {objectMode: true}', function (t) { t.plan(6) - var peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc, objectMode: true }) - var peer2 = new Peer({ config, wrtc: common.wrtc, objectMode: true }) + const peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc, objectMode: true }) + const peer2 = new Peer({ config, wrtc: common.wrtc, objectMode: true }) peer1.on('signal', function (data) { peer2.signal(data) }) @@ -86,8 +86,8 @@ test('data send/receive Buffer {objectMode: true}', function (t) { test('data send/receive Uint8Array {objectMode: true}', function (t) { t.plan(6) - var peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc, objectMode: true }) - var peer2 = new Peer({ config, wrtc: common.wrtc, objectMode: true }) + const peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc, objectMode: true }) + const peer2 = new Peer({ config, wrtc: common.wrtc, objectMode: true }) peer1.on('signal', function (data) { peer2.signal(data) }) @@ -124,8 +124,8 @@ test('data send/receive Uint8Array {objectMode: true}', function (t) { test('data send/receive ArrayBuffer {objectMode: true}', function (t) { t.plan(6) - var peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc, objectMode: true }) - var peer2 = new Peer({ config, wrtc: common.wrtc, objectMode: true }) + const peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc, objectMode: true }) + const peer2 = new Peer({ config, wrtc: common.wrtc, objectMode: true }) peer1.on('signal', function (data) { peer2.signal(data) }) diff --git a/test/stream.js b/test/stream.js index 4b02bfc8..55993987 100644 --- a/test/stream.js +++ b/test/stream.js @@ -1,9 +1,9 @@ -var common = require('./common') -var Peer = require('../') -var str = require('string-to-stream') -var test = require('tape') +const common = require('./common') +const Peer = require('../') +const str = require('string-to-stream') +const test = require('tape') -var config +let config test('get config', function (t) { common.getConfig(function (err, _config) { if (err) return t.fail(err) @@ -16,8 +16,8 @@ test('duplex stream: send data before "connect" event', function (t) { t.plan(9) t.timeoutAfter(20000) - var peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc }) - var peer2 = new Peer({ config, wrtc: common.wrtc }) + const peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc }) + const peer2 = new Peer({ config, wrtc: common.wrtc }) peer1.on('signal', function (data) { if (!peer2.destroyed) peer2.signal(data) }) peer2.on('signal', function (data) { if (!peer1.destroyed) peer1.signal(data) }) @@ -52,8 +52,8 @@ test('duplex stream: send data one-way', function (t) { t.plan(9) t.timeoutAfter(20000) - var peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc }) - var peer2 = new Peer({ config, wrtc: common.wrtc }) + const peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc }) + const peer2 = new Peer({ config, wrtc: common.wrtc }) peer1.on('signal', function (data) { peer2.signal(data) }) peer2.on('signal', function (data) { peer1.signal(data) }) peer1.on('connect', tryTest) diff --git a/test/trickle.js b/test/trickle.js index f3354e37..3d2a5fd5 100644 --- a/test/trickle.js +++ b/test/trickle.js @@ -1,8 +1,8 @@ -var common = require('./common') -var Peer = require('../') -var test = require('tape') +const common = require('./common') +const Peer = require('../') +const test = require('tape') -var config +let config test('get config', function (t) { common.getConfig(function (err, _config) { if (err) return t.fail(err) @@ -14,16 +14,16 @@ test('get config', function (t) { test('disable trickle', function (t) { t.plan(8) - var peer1 = new Peer({ config, initiator: true, trickle: false, wrtc: common.wrtc }) - var peer2 = new Peer({ config, trickle: false, wrtc: common.wrtc }) + const peer1 = new Peer({ config, initiator: true, trickle: false, wrtc: common.wrtc }) + const peer2 = new Peer({ config, trickle: false, wrtc: common.wrtc }) - var numSignal1 = 0 + let numSignal1 = 0 peer1.on('signal', function (data) { numSignal1 += 1 peer2.signal(data) }) - var numSignal2 = 0 + let numSignal2 = 0 peer2.on('signal', function (data) { numSignal2 += 1 peer1.signal(data) @@ -60,16 +60,16 @@ test('disable trickle', function (t) { test('disable trickle (only initiator)', function (t) { t.plan(8) - var peer1 = new Peer({ config, initiator: true, trickle: false, wrtc: common.wrtc }) - var peer2 = new Peer({ config, wrtc: common.wrtc }) + const peer1 = new Peer({ config, initiator: true, trickle: false, wrtc: common.wrtc }) + const peer2 = new Peer({ config, wrtc: common.wrtc }) - var numSignal1 = 0 + let numSignal1 = 0 peer1.on('signal', function (data) { numSignal1 += 1 peer2.signal(data) }) - var numSignal2 = 0 + let numSignal2 = 0 peer2.on('signal', function (data) { numSignal2 += 1 peer1.signal(data) @@ -106,16 +106,16 @@ test('disable trickle (only initiator)', function (t) { test('disable trickle (only receiver)', function (t) { t.plan(8) - var peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc }) - var peer2 = new Peer({ config, trickle: false, wrtc: common.wrtc }) + const peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc }) + const peer2 = new Peer({ config, trickle: false, wrtc: common.wrtc }) - var numSignal1 = 0 + let numSignal1 = 0 peer1.on('signal', function (data) { numSignal1 += 1 peer2.signal(data) }) - var numSignal2 = 0 + let numSignal2 = 0 peer2.on('signal', function (data) { numSignal2 += 1 peer1.signal(data) @@ -180,8 +180,8 @@ test('null end candidate does not throw', function (t) { }) test('empty-string end candidate does not throw', function (t) { - var peer1 = new Peer({ trickle: true, config, initiator: true, wrtc: common.wrtc }) - var peer2 = new Peer({ trickle: true, config, wrtc: common.wrtc }) + const peer1 = new Peer({ trickle: true, config, initiator: true, wrtc: common.wrtc }) + const peer2 = new Peer({ trickle: true, config, wrtc: common.wrtc }) // translate all falsey candidates to null let endCandidateSent = false @@ -210,8 +210,8 @@ test('empty-string end candidate does not throw', function (t) { }) test('mDNS candidate does not throw', function (t) { - var peer1 = new Peer({ trickle: true, config, initiator: true, wrtc: common.wrtc }) - var peer2 = new Peer({ trickle: true, config, wrtc: common.wrtc }) + const peer1 = new Peer({ trickle: true, config, initiator: true, wrtc: common.wrtc }) + const peer2 = new Peer({ trickle: true, config, wrtc: common.wrtc }) peer1.on('error', () => t.fail('peer1 threw error')) peer2.on('error', () => t.fail('peer2 threw error')) @@ -232,10 +232,10 @@ test('mDNS candidate does not throw', function (t) { test('ice candidates received before description', function (t) { t.plan(3) - var peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc }) - var peer2 = new Peer({ config, wrtc: common.wrtc }) + const peer1 = new Peer({ config, initiator: true, wrtc: common.wrtc }) + const peer2 = new Peer({ config, wrtc: common.wrtc }) - var signalQueue1 = [] + const signalQueue1 = [] peer1.on('signal', function (data) { signalQueue1.push(data) if (data.candidate) { @@ -243,7 +243,7 @@ test('ice candidates received before description', function (t) { } }) - var signalQueue2 = [] + const signalQueue2 = [] peer2.on('signal', function (data) { signalQueue2.push(data) if (data.candidate) { diff --git a/test/z-cleanup.js b/test/z-cleanup.js index e43e967d..a40bba69 100644 --- a/test/z-cleanup.js +++ b/test/z-cleanup.js @@ -1,7 +1,7 @@ // This test file runs after all the others. This is where we can run the cleanup // code that is required -var test = require('tape') +const test = require('tape') test('cleanup', function (t) { // Shut down the process and any daemons