diff --git a/e2e/datachannel/serialization.js b/e2e/datachannel/serialization.js index 2d5c56e64..a6032fa43 100644 --- a/e2e/datachannel/serialization.js +++ b/e2e/datachannel/serialization.js @@ -10,10 +10,8 @@ const serialization = params.get("serialization"); (async () => { let serializers = {}; try { - const { Cbor } = await import("/dist/serializer.cbor.mjs"); const { MsgPack } = await import("/dist/serializer.msgpack.mjs"); serializers = { - Cbor, MsgPack, }; } catch (e) { diff --git a/e2e/datachannel/serialization_cbor.spec.ts b/e2e/datachannel/serialization_cbor.spec.ts deleted file mode 100644 index a04f0468f..000000000 --- a/e2e/datachannel/serialization_cbor.spec.ts +++ /dev/null @@ -1,35 +0,0 @@ -import P from "./serialization.page.js"; -import { serializationTest } from "./serializationTest.js"; -import { browser } from "@wdio/globals"; - -describe("DataChannel:CBOR", function () { - beforeAll(async function () { - await P.init(); - }); - beforeEach(async function () { - if ( - // @ts-ignore - browser.capabilities.browserName === "firefox" && - // @ts-ignore - parseInt(browser.capabilities.browserVersion) < 102 - ) { - pending("Firefox 102+ required for Streams"); - } - }); - it("should transfer numbers", serializationTest("./numbers", "Cbor")); - it("should transfer strings", serializationTest("./strings", "Cbor")); - it("should transfer long string", serializationTest("./long_string", "Cbor")); - it("should transfer objects", serializationTest("./objects", "Cbor")); - it("should transfer arrays", serializationTest("./arrays", "Cbor")); - it("should transfer dates", serializationTest("./dates", "Cbor")); - it( - "should transfer ArrayBuffers as Uint8Arrays", - serializationTest("./arraybuffers_as_uint8array", "Cbor"), - ); - it( - "should transfer TypedArrayView", - serializationTest("./typed_array_view", "Cbor"), - ); - it("should transfer Uint8Arrays", serializationTest("./Uint8Array", "Cbor")); - it("should transfer Int32Arrays", serializationTest("./Int32Array", "Cbor")); -}); diff --git a/lib/cborPeer.ts b/lib/cborPeer.ts deleted file mode 100644 index 7aa281c1f..000000000 --- a/lib/cborPeer.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Peer, type SerializerMapping } from "./peer"; -import { Cbor } from "./dataconnection/StreamConnection/Cbor"; - -export class CborPeer extends Peer { - override _serializers: SerializerMapping = { - Cbor, - default: Cbor, - }; -} diff --git a/lib/dataconnection/StreamConnection/Cbor.ts b/lib/dataconnection/StreamConnection/Cbor.ts deleted file mode 100644 index c0b93f0c1..000000000 --- a/lib/dataconnection/StreamConnection/Cbor.ts +++ /dev/null @@ -1,75 +0,0 @@ -import type { Peer } from "../../peer.js"; -import { Decoder, Encoder } from "cbor-x/index-no-eval"; -import { StreamConnection } from "./StreamConnection.js"; - -const NullValue = Symbol.for(null); - -function concatUint8Array(buffer1: Uint8Array, buffer2: Uint8Array) { - const tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength); - tmp.set(buffer1, 0); - tmp.set(buffer2, buffer1.byteLength); - return new Uint8Array(tmp.buffer); -} - -const iterateOver = async function* (stream: ReadableStream) { - const reader = stream.getReader(); - try { - while (true) { - const { done, value } = await reader.read(); - if (done) return; - yield value; - } - } finally { - reader.releaseLock(); - } -}; - -export class Cbor extends StreamConnection { - readonly serialization = "Cbor"; - private _encoder = new Encoder(); - private _decoder = new Decoder(); - private _inc; - private _decoderStream = new TransformStream({ - transform: (abchunk, controller) => { - let chunk = new Uint8Array(abchunk); - if (this._inc) { - chunk = concatUint8Array(this._inc, chunk); - this._inc = null; - } - let values; - try { - values = this._decoder.decodeMultiple(chunk); - } catch (error) { - if (error.incomplete) { - this._inc = chunk.subarray(error.lastPosition); - values = error.values; - } else throw error; - } finally { - for (let value of values || []) { - if (value === null) value = NullValue; - controller.enqueue(value); - } - } - }, - }); - - constructor(peerId: string, provider: Peer, options: any) { - super(peerId, provider, { ...options, reliable: true }); - - void this._rawReadStream.pipeTo(this._decoderStream.writable); - - (async () => { - for await (const msg of iterateOver(this._decoderStream.readable)) { - if (msg.__peerData?.type === "close") { - this.close(); - return; - } - this.emit("data", msg); - } - })(); - } - - protected override _send(data) { - return this.writer.write(this._encoder.encode(data)); - } -} diff --git a/lib/exports.ts b/lib/exports.ts index 3dd8d5175..ef2265fdb 100644 --- a/lib/exports.ts +++ b/lib/exports.ts @@ -1,6 +1,5 @@ export { util, type Util } from "./util"; import { Peer } from "./peer"; -import { CborPeer } from "./cborPeer"; import { MsgPackPeer } from "./msgPackPeer"; export type { PeerEvents, PeerOptions } from "./peer"; @@ -19,11 +18,10 @@ export * from "./enums"; export { BufferedConnection } from "./dataconnection/BufferedConnection/BufferedConnection"; export { StreamConnection } from "./dataconnection/StreamConnection/StreamConnection"; -export { Cbor } from "./dataconnection/StreamConnection/Cbor"; export { MsgPack } from "./dataconnection/StreamConnection/MsgPack"; export type { SerializerMapping } from "./peer"; -export { Peer, MsgPackPeer, CborPeer }; +export { Peer, MsgPackPeer }; export { PeerError } from "./peerError"; export default Peer; diff --git a/lib/msgPackPeer.ts b/lib/msgPackPeer.ts index e0921e716..d29c2481e 100644 --- a/lib/msgPackPeer.ts +++ b/lib/msgPackPeer.ts @@ -1,6 +1,9 @@ import { Peer, type SerializerMapping } from "./peer"; import { MsgPack } from "./exports"; +/** + * @experimental + */ export class MsgPackPeer extends Peer { override _serializers: SerializerMapping = { MsgPack, diff --git a/package-lock.json b/package-lock.json index 3ec1ffa49..397f0cd7d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,6 @@ "license": "MIT", "dependencies": { "@msgpack/msgpack": "^2.8.0", - "cbor-x": "1.5.4", "eventemitter3": "^4.0.7", "peerjs-js-binarypack": "^2.1.0", "webrtc-adapter": "^9.0.0" @@ -713,78 +712,6 @@ "integrity": "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==", "dev": true }, - "node_modules/@cbor-extract/cbor-extract-darwin-arm64": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/@cbor-extract/cbor-extract-darwin-arm64/-/cbor-extract-darwin-arm64-2.2.0.tgz", - "integrity": "sha512-P7swiOAdF7aSi0H+tHtHtr6zrpF3aAq/W9FXx5HektRvLTM2O89xCyXF3pk7pLc7QpaY7AoaE8UowVf9QBdh3w==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "darwin" - ] - }, - "node_modules/@cbor-extract/cbor-extract-darwin-x64": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/@cbor-extract/cbor-extract-darwin-x64/-/cbor-extract-darwin-x64-2.2.0.tgz", - "integrity": "sha512-1liF6fgowph0JxBbYnAS7ZlqNYLf000Qnj4KjqPNW4GViKrEql2MgZnAsExhY9LSy8dnvA4C0qHEBgPrll0z0w==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "darwin" - ] - }, - "node_modules/@cbor-extract/cbor-extract-linux-arm": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/@cbor-extract/cbor-extract-linux-arm/-/cbor-extract-linux-arm-2.2.0.tgz", - "integrity": "sha512-QeBcBXk964zOytiedMPQNZr7sg0TNavZeuUCD6ON4vEOU/25+pLhNN6EDIKJ9VLTKaZ7K7EaAriyYQ1NQ05s/Q==", - "cpu": [ - "arm" - ], - "optional": true, - "os": [ - "linux" - ] - }, - "node_modules/@cbor-extract/cbor-extract-linux-arm64": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/@cbor-extract/cbor-extract-linux-arm64/-/cbor-extract-linux-arm64-2.2.0.tgz", - "integrity": "sha512-rQvhNmDuhjTVXSPFLolmQ47/ydGOFXtbR7+wgkSY0bdOxCFept1hvg59uiLPT2fVDuJFuEy16EImo5tE2x3RsQ==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "linux" - ] - }, - "node_modules/@cbor-extract/cbor-extract-linux-x64": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/@cbor-extract/cbor-extract-linux-x64/-/cbor-extract-linux-x64-2.2.0.tgz", - "integrity": "sha512-cWLAWtT3kNLHSvP4RKDzSTX9o0wvQEEAj4SKvhWuOVZxiDAeQazr9A+PSiRILK1VYMLeDml89ohxCnUNQNQNCw==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "linux" - ] - }, - "node_modules/@cbor-extract/cbor-extract-win32-x64": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/@cbor-extract/cbor-extract-win32-x64/-/cbor-extract-win32-x64-2.2.0.tgz", - "integrity": "sha512-l2M+Z8DO2vbvADOBNLbbh9y5ST1RY5sqkWOg/58GkUPBYou/cuNZ68SGQ644f1CvZ8kcOxyZtw06+dxWHIoN/w==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "win32" - ] - }, "node_modules/@colors/colors": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.5.0.tgz", @@ -5774,35 +5701,6 @@ "cdl": "bin/cdl.js" } }, - "node_modules/cbor-extract": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/cbor-extract/-/cbor-extract-2.2.0.tgz", - "integrity": "sha512-Ig1zM66BjLfTXpNgKpvBePq271BPOvu8MR0Jl080yG7Jsl+wAZunfrwiwA+9ruzm/WEdIV5QF/bjDZTqyAIVHA==", - "hasInstallScript": true, - "optional": true, - "dependencies": { - "node-gyp-build-optional-packages": "5.1.1" - }, - "bin": { - "download-cbor-prebuilds": "bin/download-prebuilds.js" - }, - "optionalDependencies": { - "@cbor-extract/cbor-extract-darwin-arm64": "2.2.0", - "@cbor-extract/cbor-extract-darwin-x64": "2.2.0", - "@cbor-extract/cbor-extract-linux-arm": "2.2.0", - "@cbor-extract/cbor-extract-linux-arm64": "2.2.0", - "@cbor-extract/cbor-extract-linux-x64": "2.2.0", - "@cbor-extract/cbor-extract-win32-x64": "2.2.0" - } - }, - "node_modules/cbor-x": { - "version": "1.5.4", - "resolved": "https://registry.npmjs.org/cbor-x/-/cbor-x-1.5.4.tgz", - "integrity": "sha512-PVKILDn+Rf6MRhhcyzGXi5eizn1i0i3F8Fe6UMMxXBnWkalq9+C5+VTmlIjAYM4iF2IYF2N+zToqAfYOp+3rfw==", - "optionalDependencies": { - "cbor-extract": "^2.1.1" - } - }, "node_modules/chainsaw": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/chainsaw/-/chainsaw-0.1.0.tgz", @@ -11416,7 +11314,7 @@ "version": "5.1.1", "resolved": "https://registry.npmjs.org/node-gyp-build-optional-packages/-/node-gyp-build-optional-packages-5.1.1.tgz", "integrity": "sha512-+P72GAjVAbTxjjwUmwjVrqrdZROD4nf8KgpBoDxqXXTiYZZt/ud60dE5yvCSr9lRO8e8yv6kgJIC0K0PfZFVQw==", - "devOptional": true, + "dev": true, "dependencies": { "detect-libc": "^2.0.1" }, @@ -11430,7 +11328,7 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.2.tgz", "integrity": "sha512-UX6sGumvvqSaXgdKGUsgZWqcUyIXZ/vZTrlRT/iobiKhGL0zL4d3osHj3uqllWJK+i+sixDS/3COVEOFbupFyw==", - "devOptional": true, + "dev": true, "engines": { "node": ">=8" } diff --git a/package.json b/package.json index 8805a722c..ae413976b 100644 --- a/package.json +++ b/package.json @@ -107,7 +107,6 @@ "module": "dist/bundler.mjs", "browser-minified": "dist/peerjs.min.js", "browser-unminified": "dist/peerjs.js", - "browser-minified-cbor": "dist/serializer.cbor.mjs", "browser-minified-msgpack": "dist/serializer.msgpack.mjs", "types": "dist/types.d.ts", "engines": { @@ -150,16 +149,6 @@ }, "source": "lib/global.ts" }, - "browser-minified-cbor": { - "context": "browser", - "outputFormat": "esmodule", - "isLibrary": true, - "optimize": true, - "engines": { - "browsers": "chrome >= 83, edge >= 83, firefox >= 102, safari >= 15" - }, - "source": "lib/dataconnection/StreamConnection/Cbor.ts" - }, "browser-minified-msgpack": { "context": "browser", "outputFormat": "esmodule", @@ -216,7 +205,6 @@ }, "dependencies": { "@msgpack/msgpack": "^2.8.0", - "cbor-x": "1.5.4", "eventemitter3": "^4.0.7", "peerjs-js-binarypack": "^2.1.0", "webrtc-adapter": "^9.0.0"