From 4cefa1d97116d491318e0544f3d48acff1e94073 Mon Sep 17 00:00:00 2001 From: shinyoshiaki Date: Sun, 13 Oct 2024 13:50:39 +0900 Subject: [PATCH] vendoring event system --- examples/package-lock.json | 14 +++++++------- examples/package.json | 2 +- packages/common/src/index.ts | 1 + packages/dtls/src/imports/common.ts | 1 + packages/dtls/src/socket.ts | 2 +- packages/ice/src/helper.ts | 2 +- packages/ice/src/ice.ts | 2 +- packages/ice/src/imports/common.ts | 1 + packages/ice/src/stun/protocol.ts | 2 +- packages/ice/src/stun/transaction.ts | 2 +- packages/ice/src/turn/protocol.ts | 2 +- packages/rtp/src/extra/container/mp4/container.ts | 2 +- packages/rtp/src/extra/processor/depacketizer.ts | 2 +- packages/rtp/src/extra/processor/mp4.ts | 2 +- packages/rtp/src/extra/processor/nack.ts | 2 +- packages/rtp/src/extra/processor/rtcpCallback.ts | 2 +- packages/rtp/src/extra/processor/rtpCallback.ts | 2 +- packages/rtp/src/extra/processor/webm.ts | 2 +- packages/rtp/src/imports/common.ts | 1 + packages/sctp/src/helper.ts | 2 +- packages/sctp/src/imports/common.ts | 1 + packages/sctp/src/sctp.ts | 2 +- packages/webrtc/src/dataChannel.ts | 2 +- packages/webrtc/src/imports/common.ts | 1 + packages/webrtc/src/index.ts | 1 - packages/webrtc/src/media/receiver/nack.ts | 2 +- packages/webrtc/src/media/rtpReceiver.ts | 2 +- packages/webrtc/src/media/rtpSender.ts | 2 +- packages/webrtc/src/media/rtpTransceiver.ts | 2 +- packages/webrtc/src/media/sender/senderBWE.ts | 2 +- packages/webrtc/src/media/track.ts | 2 +- packages/webrtc/src/nonstandard/recorder/index.ts | 2 +- .../src/nonstandard/recorder/writer/index.ts | 2 +- .../webrtc/src/nonstandard/recorder/writer/webm.ts | 2 +- packages/webrtc/src/peerConnection.ts | 2 +- packages/webrtc/src/transport/dtls.ts | 2 +- packages/webrtc/src/transport/ice.ts | 2 +- packages/webrtc/src/transport/sctp.ts | 2 +- packages/webrtc/tests/media/rtpSender.test.ts | 1 - 39 files changed, 43 insertions(+), 39 deletions(-) create mode 100644 packages/dtls/src/imports/common.ts create mode 100644 packages/ice/src/imports/common.ts create mode 100644 packages/rtp/src/imports/common.ts create mode 100644 packages/sctp/src/imports/common.ts create mode 100644 packages/webrtc/src/imports/common.ts diff --git a/examples/package-lock.json b/examples/package-lock.json index 6025127c2..92a084868 100644 --- a/examples/package-lock.json +++ b/examples/package-lock.json @@ -41,7 +41,7 @@ "wtfnode": "^0.9.1", "xmlbuilder2": "^3.0.2", "yargs": "^17.7.2", - "zx": "^8.1.6" + "zx": "^8.1.9" }, "engines": { "node": ">=14" @@ -7187,9 +7187,9 @@ "dev": true }, "node_modules/zx": { - "version": "8.1.6", - "resolved": "https://registry.npmjs.org/zx/-/zx-8.1.6.tgz", - "integrity": "sha512-SYAriWG+i2CFqMOJcF8QayI8wprlMYQsrmP6tFD7rSPnDLcImNSW7n/8crOYvNVrB2EFgz8LAQk23U1+Y7WrKA==", + "version": "8.1.9", + "resolved": "https://registry.npmjs.org/zx/-/zx-8.1.9.tgz", + "integrity": "sha512-UHuLHphHmsBYKkAchkSrEN4nzDyagafqC9HUxtc1J7eopaScW6H9dsLJ1lmkAntnLtDTGoM8fa+jrJrXiIfKFA==", "dev": true, "license": "Apache-2.0", "bin": { @@ -12473,9 +12473,9 @@ "dev": true }, "zx": { - "version": "8.1.6", - "resolved": "https://registry.npmjs.org/zx/-/zx-8.1.6.tgz", - "integrity": "sha512-SYAriWG+i2CFqMOJcF8QayI8wprlMYQsrmP6tFD7rSPnDLcImNSW7n/8crOYvNVrB2EFgz8LAQk23U1+Y7WrKA==", + "version": "8.1.9", + "resolved": "https://registry.npmjs.org/zx/-/zx-8.1.9.tgz", + "integrity": "sha512-UHuLHphHmsBYKkAchkSrEN4nzDyagafqC9HUxtc1J7eopaScW6H9dsLJ1lmkAntnLtDTGoM8fa+jrJrXiIfKFA==", "dev": true, "requires": { "@types/fs-extra": ">=11", diff --git a/examples/package.json b/examples/package.json index 2b4182c70..83a3b4324 100644 --- a/examples/package.json +++ b/examples/package.json @@ -50,7 +50,7 @@ "wtfnode": "^0.9.1", "xmlbuilder2": "^3.0.2", "yargs": "^17.7.2", - "zx": "^8.1.6" + "zx": "^8.1.9" }, "engines": { "node": ">=14" diff --git a/packages/common/src/index.ts b/packages/common/src/index.ts index 2a1abe1c6..8b7735530 100644 --- a/packages/common/src/index.ts +++ b/packages/common/src/index.ts @@ -4,3 +4,4 @@ export * from "./promise"; export * from "./network"; export * from "./type"; export * from "./log"; +export * from "./event"; diff --git a/packages/dtls/src/imports/common.ts b/packages/dtls/src/imports/common.ts new file mode 100644 index 000000000..c432919dc --- /dev/null +++ b/packages/dtls/src/imports/common.ts @@ -0,0 +1 @@ +export * from "../../../common/src"; diff --git a/packages/dtls/src/socket.ts b/packages/dtls/src/socket.ts index 7634bc8e7..f76b63018 100644 --- a/packages/dtls/src/socket.ts +++ b/packages/dtls/src/socket.ts @@ -1,7 +1,7 @@ import { decode, types } from "@shinyoshiaki/binary-data"; import debug from "debug"; -import { Event } from "rx.mini"; import { setTimeout } from "timers/promises"; +import { Event } from "./imports/common"; import { NamedCurveAlgorithmList, diff --git a/packages/ice/src/helper.ts b/packages/ice/src/helper.ts index 6bbd5c7a3..c1fc31206 100644 --- a/packages/ice/src/helper.ts +++ b/packages/ice/src/helper.ts @@ -1,7 +1,7 @@ import { randomBytes } from "crypto"; import debug from "debug"; import type PCancelable from "p-cancelable"; -import { Event } from "rx.mini"; +import { Event } from "./imports/common"; const log = debug("werift-ice:packages/ice/src/helper.ts"); diff --git a/packages/ice/src/ice.ts b/packages/ice/src/ice.ts index 194384e8e..456b7d06f 100644 --- a/packages/ice/src/ice.ts +++ b/packages/ice/src/ice.ts @@ -6,8 +6,8 @@ import { Uint64BE } from "int64-buffer"; import isEqual from "lodash/isEqual"; import PCancelable from "p-cancelable"; -import { Event } from "rx.mini"; import timers from "timers/promises"; +import { Event } from "./imports/common"; import type { InterfaceAddresses } from "../../common/src/network"; import { Candidate, candidateFoundation, candidatePriority } from "./candidate"; diff --git a/packages/ice/src/imports/common.ts b/packages/ice/src/imports/common.ts new file mode 100644 index 000000000..c432919dc --- /dev/null +++ b/packages/ice/src/imports/common.ts @@ -0,0 +1 @@ +export * from "../../../common/src"; diff --git a/packages/ice/src/stun/protocol.ts b/packages/ice/src/stun/protocol.ts index ce8eafacf..6a68b9bbd 100644 --- a/packages/ice/src/stun/protocol.ts +++ b/packages/ice/src/stun/protocol.ts @@ -1,5 +1,5 @@ import debug from "debug"; -import { Event } from "rx.mini"; +import { Event } from "../imports/common"; import type { InterfaceAddresses } from "../../../common/src/network"; import type { Candidate } from "../candidate"; diff --git a/packages/ice/src/stun/transaction.ts b/packages/ice/src/stun/transaction.ts index 3b659cb9d..2e5ac49f3 100644 --- a/packages/ice/src/stun/transaction.ts +++ b/packages/ice/src/stun/transaction.ts @@ -1,5 +1,5 @@ import debug from "debug"; -import { Event } from "rx.mini"; +import { Event } from "../imports/common"; import { TransactionFailed, TransactionTimeout } from "../exceptions"; import type { Address, Protocol } from "../types/model"; diff --git a/packages/ice/src/turn/protocol.ts b/packages/ice/src/turn/protocol.ts index 1cc595c01..1931ef4c9 100644 --- a/packages/ice/src/turn/protocol.ts +++ b/packages/ice/src/turn/protocol.ts @@ -2,8 +2,8 @@ import { createHash } from "crypto"; import { jspack } from "@shinyoshiaki/jspack"; import debug from "debug"; import PCancelable from "p-cancelable"; -import Event, { EventDisposer } from "rx.mini"; import { setTimeout } from "timers/promises"; +import { Event, EventDisposer } from "../imports/common"; import { bufferReader, int } from "../../../common/src"; import type { InterfaceAddresses } from "../../../common/src/network"; diff --git a/packages/rtp/src/extra/container/mp4/container.ts b/packages/rtp/src/extra/container/mp4/container.ts index 4c5f1f768..332e9f3ad 100644 --- a/packages/rtp/src/extra/container/mp4/container.ts +++ b/packages/rtp/src/extra/container/mp4/container.ts @@ -1,4 +1,4 @@ -import Event from "rx.mini"; +import { Event } from "../../../imports/common"; import * as MP4 from "./mp4box"; diff --git a/packages/rtp/src/extra/processor/depacketizer.ts b/packages/rtp/src/extra/processor/depacketizer.ts index 6bab05c4c..de5af2346 100644 --- a/packages/rtp/src/extra/processor/depacketizer.ts +++ b/packages/rtp/src/extra/processor/depacketizer.ts @@ -1,5 +1,5 @@ import debug from "debug"; -import Event from "rx.mini"; +import { Event } from "../../imports/common"; import { type DepacketizerCodec, diff --git a/packages/rtp/src/extra/processor/mp4.ts b/packages/rtp/src/extra/processor/mp4.ts index f2e101a7e..a77aba4ae 100644 --- a/packages/rtp/src/extra/processor/mp4.ts +++ b/packages/rtp/src/extra/processor/mp4.ts @@ -1,4 +1,4 @@ -import Event from "rx.mini"; +import { Event } from "../../imports/common"; import { OpusRtpPayload, buffer2ArrayBuffer } from "../.."; import { diff --git a/packages/rtp/src/extra/processor/nack.ts b/packages/rtp/src/extra/processor/nack.ts index 7a804b6ea..80c04bd7e 100644 --- a/packages/rtp/src/extra/processor/nack.ts +++ b/packages/rtp/src/extra/processor/nack.ts @@ -1,5 +1,5 @@ import debug from "debug"; -import Event from "rx.mini"; +import { Event } from "../../imports/common"; import { GenericNack, diff --git a/packages/rtp/src/extra/processor/rtcpCallback.ts b/packages/rtp/src/extra/processor/rtcpCallback.ts index c4b08a2f4..f6c7b5343 100644 --- a/packages/rtp/src/extra/processor/rtcpCallback.ts +++ b/packages/rtp/src/extra/processor/rtcpCallback.ts @@ -1,4 +1,4 @@ -import Event from "rx.mini"; +import { Event } from "../../imports/common"; import type { RtcpPacket } from "../.."; import type { SimpleProcessorCallback } from "./interface"; diff --git a/packages/rtp/src/extra/processor/rtpCallback.ts b/packages/rtp/src/extra/processor/rtpCallback.ts index 9db2df1d9..7c2a4f7c6 100644 --- a/packages/rtp/src/extra/processor/rtpCallback.ts +++ b/packages/rtp/src/extra/processor/rtpCallback.ts @@ -1,4 +1,4 @@ -import Event from "rx.mini"; +import { Event } from "../../imports/common"; import { RtpPacket } from "../.."; import type { SimpleProcessorCallback } from "./interface"; diff --git a/packages/rtp/src/extra/processor/webm.ts b/packages/rtp/src/extra/processor/webm.ts index 0ea8c8953..600f17b46 100644 --- a/packages/rtp/src/extra/processor/webm.ts +++ b/packages/rtp/src/extra/processor/webm.ts @@ -1,4 +1,4 @@ -import Event from "rx.mini"; +import { Event } from "../../imports/common"; import { WEBMContainer, diff --git a/packages/rtp/src/imports/common.ts b/packages/rtp/src/imports/common.ts new file mode 100644 index 000000000..c432919dc --- /dev/null +++ b/packages/rtp/src/imports/common.ts @@ -0,0 +1 @@ +export * from "../../../common/src"; diff --git a/packages/sctp/src/helper.ts b/packages/sctp/src/helper.ts index 6883abd66..c5d33db3c 100644 --- a/packages/sctp/src/helper.ts +++ b/packages/sctp/src/helper.ts @@ -1,4 +1,4 @@ -import Event from "rx.mini"; +import { Event } from "./imports/common"; export function enumerate(arr: T[]): [number, T][] { return arr.map((v, i) => [i, v]); diff --git a/packages/sctp/src/imports/common.ts b/packages/sctp/src/imports/common.ts new file mode 100644 index 000000000..c432919dc --- /dev/null +++ b/packages/sctp/src/imports/common.ts @@ -0,0 +1 @@ +export * from "../../../common/src"; diff --git a/packages/sctp/src/sctp.ts b/packages/sctp/src/sctp.ts index a6ad57dfe..1473346ef 100644 --- a/packages/sctp/src/sctp.ts +++ b/packages/sctp/src/sctp.ts @@ -2,7 +2,7 @@ import { createHmac, randomBytes } from "crypto"; import { jspack } from "@shinyoshiaki/jspack"; import debug from "debug"; import range from "lodash/range"; -import { Event } from "rx.mini"; +import { Event } from "./imports/common"; import { random32, diff --git a/packages/webrtc/src/dataChannel.ts b/packages/webrtc/src/dataChannel.ts index f3f7b54b1..34d55909e 100644 --- a/packages/webrtc/src/dataChannel.ts +++ b/packages/webrtc/src/dataChannel.ts @@ -1,5 +1,5 @@ import debug from "debug"; -import { Event } from "rx.mini"; +import { Event } from "./imports/common"; import { EventTarget } from "./helper"; import type { RTCSctpTransport } from "./transport/sctp"; diff --git a/packages/webrtc/src/imports/common.ts b/packages/webrtc/src/imports/common.ts new file mode 100644 index 000000000..c432919dc --- /dev/null +++ b/packages/webrtc/src/imports/common.ts @@ -0,0 +1 @@ +export * from "../../../common/src"; diff --git a/packages/webrtc/src/index.ts b/packages/webrtc/src/index.ts index cbc4486bd..2280a7cba 100644 --- a/packages/webrtc/src/index.ts +++ b/packages/webrtc/src/index.ts @@ -1,4 +1,3 @@ -export * from "rx.mini"; export * from "../../common/src"; export * from "../../dtls/src/cipher/const"; export * from "../../ice/src"; diff --git a/packages/webrtc/src/media/receiver/nack.ts b/packages/webrtc/src/media/receiver/nack.ts index 1ee9203e2..cc465020d 100644 --- a/packages/webrtc/src/media/receiver/nack.ts +++ b/packages/webrtc/src/media/receiver/nack.ts @@ -1,6 +1,6 @@ import debug from "debug"; import range from "lodash/range"; -import Event from "rx.mini"; +import { Event } from "../../imports/common"; import { uint16Add } from "../../../../common/src"; import { diff --git a/packages/webrtc/src/media/rtpReceiver.ts b/packages/webrtc/src/media/rtpReceiver.ts index d4768cb4c..d6d456c18 100644 --- a/packages/webrtc/src/media/rtpReceiver.ts +++ b/packages/webrtc/src/media/rtpReceiver.ts @@ -1,7 +1,7 @@ import { debug } from "debug"; -import Event from "rx.mini"; import { setTimeout } from "timers/promises"; import { v4 as uuid } from "uuid"; +import { Event } from "../imports/common"; import { type PeerConfig, diff --git a/packages/webrtc/src/media/rtpSender.ts b/packages/webrtc/src/media/rtpSender.ts index 47cd4fd6b..8ca5a6c42 100644 --- a/packages/webrtc/src/media/rtpSender.ts +++ b/packages/webrtc/src/media/rtpSender.ts @@ -23,9 +23,9 @@ Figure 2: Example for round-trip time computation import { randomBytes } from "crypto"; import { jspack } from "@shinyoshiaki/jspack"; import debug from "debug"; -import Event from "rx.mini"; import { setTimeout } from "timers/promises"; import * as uuid from "uuid"; +import { Event } from "../imports/common"; import { codecParametersFromString } from ".."; import { random16, uint16Add, uint32Add } from "../../../common/src"; diff --git a/packages/webrtc/src/media/rtpTransceiver.ts b/packages/webrtc/src/media/rtpTransceiver.ts index fe48b7e1a..d68ecca50 100644 --- a/packages/webrtc/src/media/rtpTransceiver.ts +++ b/packages/webrtc/src/media/rtpTransceiver.ts @@ -1,5 +1,5 @@ -import Event from "rx.mini"; import * as uuid from "uuid"; +import { Event } from "../imports/common"; import type { RTCDtlsTransport } from ".."; import { SenderDirections } from "../const"; diff --git a/packages/webrtc/src/media/sender/senderBWE.ts b/packages/webrtc/src/media/sender/senderBWE.ts index aa27f3c31..392dea5b0 100644 --- a/packages/webrtc/src/media/sender/senderBWE.ts +++ b/packages/webrtc/src/media/sender/senderBWE.ts @@ -1,4 +1,4 @@ -import Event from "rx.mini"; +import { Event } from "../../imports/common"; import type { TransportWideCC } from "../../../../rtp/src"; import { Int } from "../../../../rtp/src/helper"; diff --git a/packages/webrtc/src/media/track.ts b/packages/webrtc/src/media/track.ts index 4574bb039..e94db3347 100644 --- a/packages/webrtc/src/media/track.ts +++ b/packages/webrtc/src/media/track.ts @@ -1,5 +1,5 @@ -import Event from "rx.mini"; import { v4 } from "uuid"; +import { Event } from "../imports/common"; import { type RtcpPacket, type RtpHeader, RtpPacket } from "../../../rtp/src"; import { EventTarget } from "../helper"; diff --git a/packages/webrtc/src/nonstandard/recorder/index.ts b/packages/webrtc/src/nonstandard/recorder/index.ts index daef26405..e7cbcb113 100644 --- a/packages/webrtc/src/nonstandard/recorder/index.ts +++ b/packages/webrtc/src/nonstandard/recorder/index.ts @@ -1,4 +1,4 @@ -import Event from "rx.mini"; +import { Event } from "../../imports/common"; import type { MediaStreamTrack } from "../../media/track"; import type { MediaWriter, StreamEvent } from "./writer"; import { WebmFactory } from "./writer/webm"; diff --git a/packages/webrtc/src/nonstandard/recorder/writer/index.ts b/packages/webrtc/src/nonstandard/recorder/writer/index.ts index 0ddafaeb1..481b23989 100644 --- a/packages/webrtc/src/nonstandard/recorder/writer/index.ts +++ b/packages/webrtc/src/nonstandard/recorder/writer/index.ts @@ -1,7 +1,7 @@ -import type { Event } from "rx.mini"; import type { MediaRecorderOptions } from ".."; import type { MediaStreamTrack } from "../../.."; import type { WebmOutput } from "../../../../../rtp/src/extra"; +import type { Event } from "../../../imports/common"; export abstract class MediaWriter { constructor( diff --git a/packages/webrtc/src/nonstandard/recorder/writer/webm.ts b/packages/webrtc/src/nonstandard/recorder/writer/webm.ts index 45793acb3..cc12f7612 100644 --- a/packages/webrtc/src/nonstandard/recorder/writer/webm.ts +++ b/packages/webrtc/src/nonstandard/recorder/writer/webm.ts @@ -1,5 +1,5 @@ import { unlink } from "fs/promises"; -import { EventDisposer } from "rx.mini"; +import { EventDisposer } from "../../../imports/common"; import { MediaWriter } from "."; import { type MediaStreamTrack, WeriftError } from "../../.."; diff --git a/packages/webrtc/src/peerConnection.ts b/packages/webrtc/src/peerConnection.ts index 0876c62f6..9a069cd2c 100644 --- a/packages/webrtc/src/peerConnection.ts +++ b/packages/webrtc/src/peerConnection.ts @@ -1,8 +1,8 @@ import debug from "debug"; import cloneDeep from "lodash/cloneDeep"; import isEqual from "lodash/isEqual"; -import Event from "rx.mini"; import * as uuid from "uuid"; +import { Event } from "./imports/common"; import { type Address, diff --git a/packages/webrtc/src/transport/dtls.ts b/packages/webrtc/src/transport/dtls.ts index eb8bfe273..1d784b5f9 100644 --- a/packages/webrtc/src/transport/dtls.ts +++ b/packages/webrtc/src/transport/dtls.ts @@ -1,8 +1,8 @@ import { Certificate, PrivateKey } from "@fidm/x509"; import debug from "debug"; -import Event from "rx.mini"; import { setTimeout } from "timers/promises"; import { v4 } from "uuid"; +import { Event } from "../imports/common"; import { DtlsClient, diff --git a/packages/webrtc/src/transport/ice.ts b/packages/webrtc/src/transport/ice.ts index 9036905b6..6ffac63f8 100644 --- a/packages/webrtc/src/transport/ice.ts +++ b/packages/webrtc/src/transport/ice.ts @@ -1,6 +1,6 @@ import debug from "debug"; -import Event from "rx.mini"; import { v4 } from "uuid"; +import { Event } from "../imports/common"; import { Candidate, Connection, type IceOptions } from "../../../ice/src"; import { candidateFromSdp, candidateToSdp } from "../sdp"; diff --git a/packages/webrtc/src/transport/sctp.ts b/packages/webrtc/src/transport/sctp.ts index da95ca863..fe94ad28b 100644 --- a/packages/webrtc/src/transport/sctp.ts +++ b/packages/webrtc/src/transport/sctp.ts @@ -1,7 +1,7 @@ import { jspack } from "@shinyoshiaki/jspack"; import debug from "debug"; -import { Event } from "rx.mini"; import * as uuid from "uuid"; +import { Event } from "../imports/common"; import { SCTP, SCTP_STATE, type Transport } from "../../../sctp/src"; import { diff --git a/packages/webrtc/tests/media/rtpSender.test.ts b/packages/webrtc/tests/media/rtpSender.test.ts index 768dce3a9..8ab36a1e7 100644 --- a/packages/webrtc/tests/media/rtpSender.test.ts +++ b/packages/webrtc/tests/media/rtpSender.test.ts @@ -23,7 +23,6 @@ describe("media/rtpSender", () => { expect(spy).toBeCalledTimes(2); track.stop(); - expect(() => track.onReceiveRtp.execute(rtp)).toThrow(); expect(spy).toBeCalledTimes(2); });