Skip to content

Commit 973907d

Browse files
committed
BREAKING CHANGE: removing streamx support
Completely removing streamx support (and the .pipe method at the same time) This will allow easier bundling in both environments (Node + Browser), since streamx is not browser native.
1 parent 17dd7ca commit 973907d

File tree

14 files changed

+76
-1173
lines changed

14 files changed

+76
-1173
lines changed

β€ŽREADME.mdβ€Ž

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
#### Simple WebRTC video, voice, and data channels
1313

14-
This package is a more up to date version of feross's simple-peer, it does away with node:stream and node:buffer in favor of streamx and Uint8Array, making the module a lot smaller, additionally it provides `@thaunknown/simple-peer/lite.js` which is the same peer implementation, but without MediaTrack and MediaStream handling, just pure Uint8/String data.
14+
This package is a more up to date version of feross's simple-peer, it uses `EventEmitter` and `Uint8Array` instead of node streams and buffers, making the module lighter and fully compatible with browser bundlers like Vite. It provides `@thaunknown/simple-peer/lite.js` which is the same peer implementation, but without MediaTrack and MediaStream handling, just pure Uint8/String data.
1515

16-
It's fully backwards compatible with feross's version.
16+
> **Breaking change:** This version no longer extends `Duplex` stream. The `pipe()` method is not available. Use `peer.on('data', ...)` and `peer.send()` / `peer.write()` instead.
1717
1818
## features
1919

@@ -22,7 +22,7 @@ It's fully backwards compatible with feross's version.
2222
- supports **video/voice streams**
2323
- supports **data channel**
2424
- text and binary data
25-
- node.js [duplex stream](http://nodejs.org/api/stream.html) interface
25+
- event-based API with `on('data')`, `send()`, and `write()`
2626
- supports advanced options like:
2727
- enable/disable [trickle ICE candidates](http://webrtchacks.com/trickle-ice/)
2828
- manually set config options
@@ -318,7 +318,7 @@ Send text/binary data to the remote peer. `data` can be any of several types: `S
318318
`Buffer` (see [buffer](https://github.com/feross/buffer)), `ArrayBufferView` (`Uint8Array`,
319319
etc.), `ArrayBuffer`, or `Blob` (in browsers that support it).
320320

321-
Note: If this method is called before the `peer.on('connect')` event has fired, then an exception will be thrown. Use `peer.write(data)` (which is inherited from the node.js [duplex stream](http://nodejs.org/api/stream.html) interface) if you want this data to be buffered instead.
321+
Note: If this method is called before the `peer.on('connect')` event has fired, then an exception will be thrown. Use `peer.write(data)` if you want this data to be buffered instead.
322322

323323
### `peer.addStream(stream)`
324324

@@ -365,11 +365,9 @@ if (Peer.WEBRTC_SUPPORT) {
365365
}
366366
```
367367

368-
### duplex stream
368+
### data channel API
369369

370-
`Peer` objects are instances of `stream.Duplex`. They behave very similarly to a
371-
`net.Socket` from the node core `net` module. The duplex stream reads/writes to the data
372-
channel.
370+
`Peer` objects extend `EventEmitter` and provide a simple API for sending and receiving data.
373371

374372
```js
375373
var peer = new Peer(opts)
@@ -380,6 +378,8 @@ peer.on('data', function (chunk) {
380378
})
381379
```
382380

381+
> **Note:** The `pipe()` method is no longer supported. Use `peer.on('data', ...)` to receive data and `peer.send()` / `peer.write()` to send data.
382+
383383
## events
384384

385385
`Peer` objects are instance of `EventEmitter`. Take a look at the [nodejs events documentation](https://nodejs.org/api/events.html) for more information.
@@ -581,10 +581,9 @@ and sending the buffer at some later point in time. We immediately call
581581
`channel.send()` on the data channel. So it should be fine to mutate the buffer
582582
right afterward.
583583

584-
However, beware that `peer.write(buf)` (a writable stream method) does not have
585-
the same contract. It will potentially buffer the data and call
586-
`channel.send()` at a future point in time, so definitely don't assume it's
587-
safe to mutate the buffer.
584+
However, beware that `peer.write(buf)` does not have the same contract. It will
585+
potentially buffer the data and call `channel.send()` at a future point in time,
586+
so definitely don't assume it's safe to mutate the buffer.
588587

589588

590589
## connection does not work on some networks?

β€Žfull.jsβ€Ž

Lines changed: 0 additions & 2 deletions
This file was deleted.

β€Žindex.d.tsβ€Ž

Lines changed: 0 additions & 42 deletions
This file was deleted.

β€Žindex.d.ts.mapβ€Ž

Lines changed: 0 additions & 1 deletion
This file was deleted.

β€Žindex.js.mapβ€Ž

Lines changed: 0 additions & 1 deletion
This file was deleted.

β€Žlite.d.tsβ€Ž

Lines changed: 0 additions & 156 deletions
This file was deleted.

0 commit comments

Comments
Β (0)