werift 0.24.0 → 0.24.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/lib/common/src/binary.js +2 -3
  2. package/lib/common/src/binary.js.map +1 -1
  3. package/lib/ice/src/ice.js +4 -9
  4. package/lib/ice/src/ice.js.map +1 -1
  5. package/lib/ice/src/internal/selectAddresses.d.ts +9 -0
  6. package/lib/ice/src/internal/selectAddresses.js +40 -0
  7. package/lib/ice/src/internal/selectAddresses.js.map +1 -0
  8. package/lib/ice/src/utils.js +2 -31
  9. package/lib/ice/src/utils.js.map +1 -1
  10. package/lib/ice-server/src/stun/attributes.js +9 -47
  11. package/lib/ice-server/src/stun/attributes.js.map +1 -1
  12. package/lib/ice-server/src/stun/ip.d.ts +12 -0
  13. package/lib/ice-server/src/stun/ip.js +88 -0
  14. package/lib/ice-server/src/stun/ip.js.map +1 -0
  15. package/lib/index.mjs +217 -130
  16. package/lib/nonstandard/index.mjs +121 -54
  17. package/lib/rtp/src/codec/av1.js +11 -5
  18. package/lib/rtp/src/codec/av1.js.map +1 -1
  19. package/lib/rtp/src/codec/leb128.d.ts +5 -0
  20. package/lib/rtp/src/codec/leb128.js +24 -0
  21. package/lib/rtp/src/codec/leb128.js.map +1 -0
  22. package/lib/rtp/src/rtp/rtx.js +4 -6
  23. package/lib/rtp/src/rtp/rtx.js.map +1 -1
  24. package/lib/rtp/src/srtp/context/context.d.ts +2 -0
  25. package/lib/rtp/src/srtp/context/context.js +12 -12
  26. package/lib/rtp/src/srtp/context/context.js.map +1 -1
  27. package/lib/sctp/src/param.js +31 -15
  28. package/lib/sctp/src/param.js.map +1 -1
  29. package/lib/sctp/src/sctp.js +10 -9
  30. package/lib/sctp/src/sctp.js.map +1 -1
  31. package/lib/webrtc/src/media/rtpSender.js +2 -3
  32. package/lib/webrtc/src/media/rtpSender.js.map +1 -1
  33. package/lib/webrtc/src/sdp.js +1 -35
  34. package/lib/webrtc/src/sdp.js.map +1 -1
  35. package/lib/webrtc/src/transport/sctp.js +17 -16
  36. package/lib/webrtc/src/transport/sctp.js.map +1 -1
  37. package/package.json +1 -7
package/lib/index.mjs CHANGED
@@ -1,11 +1,10 @@
1
1
  // ../common/src/binary.ts
2
2
  import { randomBytes } from "crypto";
3
- import { jspack } from "@shinyoshiaki/jspack";
4
3
  function random16() {
5
- return jspack.Unpack("!H", randomBytes(2))[0];
4
+ return randomBytes(2).readUInt16BE(0);
6
5
  }
7
6
  function random32() {
8
- return jspack.Unpack("!L", randomBytes(4))[0];
7
+ return randomBytes(4).readUInt32BE(0);
9
8
  }
10
9
  function bufferXor(a, b) {
11
10
  if (a.length !== b.length) {
@@ -2600,8 +2599,25 @@ var saltLength = (profile) => {
2600
2599
  }
2601
2600
  };
2602
2601
 
2602
+ // ../rtp/src/codec/leb128.ts
2603
+ function leb128encode(value) {
2604
+ if (!Number.isInteger(value) || value < 0 || !Number.isSafeInteger(value)) {
2605
+ throw new Error("LEB128 encode requires a non-negative safe integer");
2606
+ }
2607
+ const bytes = [];
2608
+ let remaining = value;
2609
+ do {
2610
+ let byte = remaining & 127;
2611
+ remaining = Math.floor(remaining / 128);
2612
+ if (remaining !== 0) {
2613
+ byte |= 128;
2614
+ }
2615
+ bytes.push(byte);
2616
+ } while (remaining !== 0);
2617
+ return Buffer.from(bytes);
2618
+ }
2619
+
2603
2620
  // ../rtp/src/codec/av1.ts
2604
- import { LEB128 } from "@minhducsun2002/leb128";
2605
2621
  var log3 = debug("werift-rtp : packages/rtp/src/codec/av1.ts");
2606
2622
  var AV1RtpPayload = class _AV1RtpPayload {
2607
2623
  /**
@@ -2731,7 +2747,7 @@ var AV1Obu = class _AV1Obu {
2731
2747
  const header = new BitWriter2(8).set(this.obu_forbidden_bit).set(OBU_TYPE_IDS[this.obu_type], 4).set(this.obu_extension_flag).set(this.obu_has_size_field).set(this.obu_reserved_1bit).buffer;
2732
2748
  let obuSize = Buffer.alloc(0);
2733
2749
  if (this.obu_has_size_field) {
2734
- obuSize = LEB128.encode(this.payload.length);
2750
+ obuSize = leb128encode(this.payload.length);
2735
2751
  }
2736
2752
  return Buffer.concat([header, obuSize, this.payload]);
2737
2753
  }
@@ -2740,14 +2756,20 @@ function leb128decode(buf) {
2740
2756
  let value = 0;
2741
2757
  let leb128bytes = 0;
2742
2758
  for (let i = 0; i < 8; i++) {
2759
+ if (i >= buf.length) {
2760
+ throw new Error("LEB128 decode incomplete");
2761
+ }
2743
2762
  const leb128byte = buf.readUInt8(i);
2744
- value |= (leb128byte & 127) << i * 7;
2763
+ value += (leb128byte & 127) * 128 ** i;
2745
2764
  leb128bytes++;
2746
2765
  if (!(leb128byte & 128)) {
2747
- break;
2766
+ if (!Number.isSafeInteger(value)) {
2767
+ throw new Error("LEB128 value exceeds safe integer");
2768
+ }
2769
+ return [value, leb128bytes];
2748
2770
  }
2749
2771
  }
2750
- return [value, leb128bytes];
2772
+ throw new Error("LEB128 decode incomplete");
2751
2773
  }
2752
2774
  var OBU_TYPES = {
2753
2775
  0: "Reserved",
@@ -4694,13 +4716,12 @@ var RtpPacket = class _RtpPacket {
4694
4716
  };
4695
4717
 
4696
4718
  // ../rtp/src/rtp/rtx.ts
4697
- import { jspack as jspack2 } from "@shinyoshiaki/jspack";
4698
4719
  function unwrapRtx(rtx, payloadType, ssrc) {
4699
4720
  const packet = new RtpPacket(
4700
4721
  new RtpHeader({
4701
4722
  payloadType,
4702
4723
  marker: rtx.header.marker,
4703
- sequenceNumber: jspack2.Unpack("!H", rtx.payload.subarray(0, 2))[0],
4724
+ sequenceNumber: rtx.payload.readUInt16BE(0),
4704
4725
  timestamp: rtx.header.timestamp,
4705
4726
  ssrc
4706
4727
  }),
@@ -4709,6 +4730,8 @@ function unwrapRtx(rtx, payloadType, ssrc) {
4709
4730
  return packet;
4710
4731
  }
4711
4732
  function wrapRtx(packet, payloadType, sequenceNumber, ssrc) {
4733
+ const originalSequence = Buffer.allocUnsafe(2);
4734
+ originalSequence.writeUInt16BE(packet.header.sequenceNumber, 0);
4712
4735
  const rtx = new RtpPacket(
4713
4736
  new RtpHeader({
4714
4737
  payloadType,
@@ -4719,17 +4742,13 @@ function wrapRtx(packet, payloadType, sequenceNumber, ssrc) {
4719
4742
  csrc: packet.header.csrc,
4720
4743
  extensions: packet.header.extensions
4721
4744
  }),
4722
- Buffer.concat([
4723
- Buffer.from(jspack2.Pack("!H", [packet.header.sequenceNumber])),
4724
- packet.payload
4725
- ])
4745
+ Buffer.concat([originalSequence, packet.payload])
4726
4746
  );
4727
4747
  return rtx;
4728
4748
  }
4729
4749
 
4730
4750
  // ../rtp/src/srtp/context/context.ts
4731
- import { createHmac as createHmac3 } from "crypto";
4732
- import AES from "aes-js";
4751
+ import { createCipheriv as createCipheriv4, createHmac as createHmac3 } from "crypto";
4733
4752
 
4734
4753
  // ../rtp/src/srtp/cipher/ctr.ts
4735
4754
  import {
@@ -5117,6 +5136,11 @@ function finalizeAuthenticatedDecryption(decipher, packetType) {
5117
5136
  }
5118
5137
 
5119
5138
  // ../rtp/src/srtp/context/context.ts
5139
+ function aes128EcbEncrypt(key, plaintext) {
5140
+ const cipher = createCipheriv4("aes-128-ecb", key, null);
5141
+ cipher.setAutoPadding(false);
5142
+ return Buffer.concat([cipher.update(plaintext), cipher.final()]);
5143
+ }
5120
5144
  var Context = class {
5121
5145
  constructor(masterKey, masterSalt, profile) {
5122
5146
  this.masterKey = masterKey;
@@ -5183,8 +5207,7 @@ var Context = class {
5183
5207
  sessionKey[j] = sessionKey[j] ^ labelAndIndexOverKdr[i];
5184
5208
  }
5185
5209
  sessionKey = Buffer.concat([sessionKey, Buffer.from([0, 0])]);
5186
- const block = new AES.AES(this.masterKey);
5187
- return Buffer.from(block.encrypt(sessionKey));
5210
+ return aes128EcbEncrypt(this.masterKey, sessionKey);
5188
5211
  }
5189
5212
  generateSessionSalt(label) {
5190
5213
  let sessionSalt = Buffer.from(this.masterSalt);
@@ -5201,8 +5224,7 @@ var Context = class {
5201
5224
  sessionSalt[j] = sessionSalt[j] ^ labelAndIndexOverKdr[i];
5202
5225
  }
5203
5226
  sessionSalt = Buffer.concat([sessionSalt, Buffer.from([0, 0])]);
5204
- const block = new AES.AES(this.masterKey);
5205
- sessionSalt = Buffer.from(block.encrypt(sessionSalt));
5227
+ sessionSalt = aes128EcbEncrypt(this.masterKey, sessionSalt);
5206
5228
  return sessionSalt.subarray(0, 14);
5207
5229
  }
5208
5230
  generateSessionAuthTag(label) {
@@ -5227,9 +5249,8 @@ var Context = class {
5227
5249
  sessionAuthTag,
5228
5250
  Buffer.from([0, 1])
5229
5251
  ]);
5230
- const block = new AES.AES(this.masterKey);
5231
- firstRun = Buffer.from(block.encrypt(firstRun));
5232
- secondRun = Buffer.from(block.encrypt(secondRun));
5252
+ firstRun = aes128EcbEncrypt(this.masterKey, firstRun);
5253
+ secondRun = aes128EcbEncrypt(this.masterKey, secondRun);
5233
5254
  return Buffer.concat([firstRun, secondRun.subarray(0, 4)]);
5234
5255
  }
5235
5256
  getSrtpSsrcState(ssrc) {
@@ -6735,17 +6756,82 @@ import { connect as connect3, createServer } from "node:net";
6735
6756
  // ../ice-server/src/stun/message.ts
6736
6757
  import { createHmac as createHmac4, randomBytes as randomBytes5 } from "crypto";
6737
6758
 
6759
+ // ../ice-server/src/stun/ip.ts
6760
+ import { isIPv4, isIPv6 } from "node:net";
6761
+ function ipAddressToBuffer(address) {
6762
+ if (isIPv4(address)) {
6763
+ const buf = Buffer.allocUnsafe(4);
6764
+ const parts = address.split(".");
6765
+ for (let i = 0; i < 4; i++) {
6766
+ buf[i] = Number(parts[i]) & 255;
6767
+ }
6768
+ return buf;
6769
+ }
6770
+ if (!isIPv6(address)) {
6771
+ throw new Error(`Invalid ip address: ${address}`);
6772
+ }
6773
+ const sections = address.split(":", 8);
6774
+ for (let i = 0; i < sections.length; i++) {
6775
+ let v4Buffer;
6776
+ if (isIPv4(sections[i])) {
6777
+ v4Buffer = ipAddressToBuffer(sections[i]);
6778
+ sections[i] = v4Buffer.subarray(0, 2).toString("hex");
6779
+ }
6780
+ if (v4Buffer && ++i < 8) {
6781
+ sections.splice(i, 0, v4Buffer.subarray(2, 4).toString("hex"));
6782
+ }
6783
+ }
6784
+ if (sections[0] === "") {
6785
+ while (sections.length < 8) sections.unshift("0");
6786
+ } else if (sections[sections.length - 1] === "") {
6787
+ while (sections.length < 8) sections.push("0");
6788
+ } else if (sections.length < 8) {
6789
+ let emptyIndex = 0;
6790
+ for (; emptyIndex < sections.length && sections[emptyIndex] !== ""; emptyIndex++) ;
6791
+ const zeros = [];
6792
+ for (let n = 9 - sections.length; n > 0; n--) {
6793
+ zeros.push("0");
6794
+ }
6795
+ sections.splice(emptyIndex, 1, ...zeros);
6796
+ }
6797
+ const result = Buffer.allocUnsafe(16);
6798
+ let offset = 0;
6799
+ for (const section of sections) {
6800
+ const word = Number.parseInt(section, 16) || 0;
6801
+ result[offset++] = word >> 8 & 255;
6802
+ result[offset++] = word & 255;
6803
+ }
6804
+ return result;
6805
+ }
6806
+ function bufferToIpAddress(buf) {
6807
+ if (buf.length === 4) {
6808
+ return `${buf[0]}.${buf[1]}.${buf[2]}.${buf[3]}`;
6809
+ }
6810
+ if (buf.length !== 16) {
6811
+ throw new Error(`Invalid ip address buffer length: ${buf.length}`);
6812
+ }
6813
+ const hextets = [];
6814
+ for (let i = 0; i < 16; i += 2) {
6815
+ hextets.push(buf.readUInt16BE(i).toString(16));
6816
+ }
6817
+ let result = hextets.join(":");
6818
+ result = result.replace(/(^|:)0(:0)*:0(:|$)/, "$1::$3");
6819
+ result = result.replace(/:{3,4}/, "::");
6820
+ return result;
6821
+ }
6822
+ function isIpV4Address(address) {
6823
+ return isIPv4(address);
6824
+ }
6825
+
6738
6826
  // ../ice-server/src/stun/attributes.ts
6739
- import * as Int64 from "int64-buffer";
6740
- import nodeIp from "ip";
6741
6827
  function packAddress(value) {
6742
6828
  const [address] = value;
6743
- const protocol = nodeIp.isV4Format(address) ? IPV4_PROTOCOL : IPV6_PROTOCOL;
6829
+ const protocol = isIpV4Address(address) ? IPV4_PROTOCOL : IPV6_PROTOCOL;
6744
6830
  const buffer2 = Buffer.alloc(4);
6745
6831
  buffer2.writeUInt8(0, 0);
6746
6832
  buffer2.writeUInt8(protocol, 1);
6747
6833
  buffer2.writeUInt16BE(value[1], 2);
6748
- return Buffer.concat([buffer2, nodeIp.toBuffer(address)]);
6834
+ return Buffer.concat([buffer2, ipAddressToBuffer(address)]);
6749
6835
  }
6750
6836
  function unpackErrorCode(data) {
6751
6837
  if (data.length < 4) {
@@ -6768,12 +6854,12 @@ function unpackAddress(data) {
6768
6854
  if (address.length !== 4) {
6769
6855
  throw new Error("STUN address has invalid length for IPv4");
6770
6856
  }
6771
- return [nodeIp.toString(address), port];
6857
+ return [bufferToIpAddress(address), port];
6772
6858
  case IPV6_PROTOCOL:
6773
6859
  if (address.length !== 16) {
6774
6860
  throw new Error("STUN address has invalid length for IPv6");
6775
6861
  }
6776
- return [nodeIp.toString(address), port];
6862
+ return [bufferToIpAddress(address), port];
6777
6863
  default:
6778
6864
  throw new Error("STUN address has unknown protocol");
6779
6865
  }
@@ -6836,12 +6922,11 @@ var packUnsignedShort = (value) => {
6836
6922
  };
6837
6923
  var unpackUnsignedShort = (data) => data.readUInt16BE(0);
6838
6924
  var packUnsigned64 = (value) => {
6839
- return new Int64.Int64BE(value.toString()).toBuffer();
6840
- };
6841
- var unpackUnsigned64 = (data) => {
6842
- const int2 = new Int64.Int64BE(data);
6843
- return BigInt(int2.toString());
6925
+ const buffer2 = Buffer.allocUnsafe(8);
6926
+ buffer2.writeBigUInt64BE(value, 0);
6927
+ return buffer2;
6844
6928
  };
6929
+ var unpackUnsigned64 = (data) => data.readBigUInt64BE(0);
6845
6930
  var packString = (value) => Buffer.from(value, "utf8");
6846
6931
  var unpackString = (data) => data.toString("utf8");
6847
6932
  var packSoftware = (value) => {
@@ -8086,7 +8171,7 @@ function makeIntegrityKey(username, realm, password) {
8086
8171
 
8087
8172
  // ../ice/src/candidate.ts
8088
8173
  import { createHash as createHash3, randomUUID } from "crypto";
8089
- import { isIPv4 } from "net";
8174
+ import { isIPv4 as isIPv42 } from "net";
8090
8175
  var Candidate = class _Candidate {
8091
8176
  constructor(foundation, component, transport, priority, host, port, type, relatedAddress, relatedPort, tcptype, generation, ufrag) {
8092
8177
  this.foundation = foundation;
@@ -8151,8 +8236,8 @@ var Candidate = class _Candidate {
8151
8236
  );
8152
8237
  }
8153
8238
  canPairWith(other) {
8154
- const a = isIPv4(this.host);
8155
- const b = isIPv4(other.host);
8239
+ const a = isIPv42(this.host);
8240
+ const b = isIPv42(other.host);
8156
8241
  return this.component === other.component && this.transport.toLowerCase() === other.transport.toLowerCase() && canPairTcpCandidates(this, other) && a === b;
8157
8242
  }
8158
8243
  toSdp() {
@@ -8257,10 +8342,8 @@ function remoteTcpTypeForIncoming(localTcpType) {
8257
8342
 
8258
8343
  // ../ice/src/ice.ts
8259
8344
  import { randomBytes as randomBytes7 } from "crypto";
8260
- import { isIPv4 as isIPv42 } from "net";
8261
- import * as Int642 from "int64-buffer";
8345
+ import { isIPv4 as isIPv43 } from "net";
8262
8346
  import * as timers from "node:timers/promises";
8263
- import isEqual from "fast-deep-equal";
8264
8347
 
8265
8348
  // ../ice/src/dns/lookup.ts
8266
8349
  import mdns from "multicast-dns";
@@ -8461,7 +8544,34 @@ function validateAddress(addr) {
8461
8544
 
8462
8545
  // ../ice/src/utils.ts
8463
8546
  import * as os from "node:os";
8464
- import nodeIp2 from "ip";
8547
+
8548
+ // ../ice/src/internal/selectAddresses.ts
8549
+ function selectAddressesFromInterfaces(interfaces, family, options = {}, isLinkLocal) {
8550
+ const costlyNetworks = ["ipsec", "tun", "utun", "tap"];
8551
+ const banNetworks = ["vmnet", "veth"];
8552
+ const { useLinkLocalAddress } = options;
8553
+ const all = Object.keys(interfaces).map((nic) => {
8554
+ for (const word of [...costlyNetworks, ...banNetworks]) {
8555
+ if (nic.startsWith(word)) {
8556
+ return {
8557
+ nic,
8558
+ addresses: []
8559
+ };
8560
+ }
8561
+ }
8562
+ const addresses = (interfaces[nic] ?? []).filter(
8563
+ (details) => normalizeFamilyNodeV18(details.family) === family && !details.internal && (useLinkLocalAddress ? true : !isLinkLocal(details))
8564
+ );
8565
+ return {
8566
+ nic,
8567
+ addresses: addresses.map((address) => address.address)
8568
+ };
8569
+ }).filter((address) => !!address);
8570
+ all.sort((a, b) => a.nic.localeCompare(b.nic));
8571
+ return Object.values(all).flatMap((entry) => entry.addresses);
8572
+ }
8573
+
8574
+ // ../ice/src/utils.ts
8465
8575
  var logger = debug("werift-ice : packages/ice/src/utils.ts");
8466
8576
  async function getGlobalIp(stunServer, interfaceAddresses) {
8467
8577
  const protocol = new StunProtocol();
@@ -8481,29 +8591,14 @@ function isLinkLocalAddress(info) {
8481
8591
  function nodeIpAddress(family, {
8482
8592
  useLinkLocalAddress
8483
8593
  } = {}) {
8484
- const costlyNetworks = ["ipsec", "tun", "utun", "tap"];
8485
- const banNetworks = ["vmnet", "veth"];
8486
8594
  const interfaces = os.networkInterfaces();
8487
8595
  logger(interfaces);
8488
- const all = Object.keys(interfaces).map((nic) => {
8489
- for (const word of [...costlyNetworks, ...banNetworks]) {
8490
- if (nic.startsWith(word)) {
8491
- return {
8492
- nic,
8493
- addresses: []
8494
- };
8495
- }
8496
- }
8497
- const addresses = interfaces[nic].filter(
8498
- (details) => normalizeFamilyNodeV18(details.family) === family && !nodeIp2.isLoopback(details.address) && (useLinkLocalAddress ? true : !isLinkLocalAddress(details))
8499
- );
8500
- return {
8501
- nic,
8502
- addresses: addresses.map((address) => address.address)
8503
- };
8504
- }).filter((address) => !!address);
8505
- all.sort((a, b) => a.nic.localeCompare(b.nic));
8506
- return Object.values(all).flatMap((entry) => entry.addresses);
8596
+ return selectAddressesFromInterfaces(
8597
+ interfaces,
8598
+ family,
8599
+ { useLinkLocalAddress },
8600
+ isLinkLocalAddress
8601
+ );
8507
8602
  }
8508
8603
  function getHostAddresses(useIpv4, useIpv6, options = {}) {
8509
8604
  const address = [];
@@ -8556,9 +8651,7 @@ var Connection = class {
8556
8651
  localCandidatesEnd = false;
8557
8652
  generation = -1;
8558
8653
  userHistory = {};
8559
- tieBreaker = BigInt(
8560
- new Int642.Uint64BE(randomBytes7(64)).toString()
8561
- );
8654
+ tieBreaker = randomBytes7(8).readBigUInt64BE(0);
8562
8655
  state = "new";
8563
8656
  lookup;
8564
8657
  _remoteCandidates = [];
@@ -8752,7 +8845,7 @@ var Connection = class {
8752
8845
  this.ensureProtocol(protocol);
8753
8846
  try {
8754
8847
  await protocol.connectionMade(
8755
- isIPv42(address),
8848
+ isIPv43(address),
8756
8849
  this.options.portRange,
8757
8850
  this.options.interfaceAddresses
8758
8851
  );
@@ -8853,7 +8946,7 @@ var Connection = class {
8853
8946
  const stunCandidatePromise = new Promise(
8854
8947
  async (r, f) => {
8855
8948
  const timer2 = setTimeout(f, timeout * 1e3);
8856
- if (protocol.localCandidate?.host && isIPv42(protocol.localCandidate?.host)) {
8949
+ if (protocol.localCandidate?.host && isIPv43(protocol.localCandidate?.host)) {
8857
8950
  const candidate = await serverReflexiveCandidate(
8858
8951
  protocol,
8859
8952
  stunServer
@@ -9208,7 +9301,7 @@ var Connection = class {
9208
9301
  }
9209
9302
  findPair(protocol, remoteCandidate) {
9210
9303
  const pair = this.checkList.find(
9211
- (pair2) => isEqual(pair2.protocol, protocol) && isEqual(pair2.remoteCandidate, remoteCandidate)
9304
+ (pair2) => pair2.protocol === protocol && pair2.remoteCandidate === remoteCandidate
9212
9305
  );
9213
9306
  return pair;
9214
9307
  }
@@ -9351,7 +9444,7 @@ var Connection = class {
9351
9444
  return;
9352
9445
  }
9353
9446
  }
9354
- if (!isEqual(result.addr, pair.remoteAddr)) {
9447
+ if (result.addr[0] !== pair.remoteAddr[0] || result.addr[1] !== pair.remoteAddr[1]) {
9355
9448
  pair.updateState(4 /* FAILED */);
9356
9449
  this.checkComplete(pair);
9357
9450
  r();
@@ -10763,8 +10856,7 @@ var StreamStatistics = class {
10763
10856
 
10764
10857
  // src/sdp.ts
10765
10858
  import { randomBytes as randomBytes9 } from "crypto";
10766
- import { isIPv4 as isIPv43 } from "net";
10767
- import * as Int643 from "int64-buffer";
10859
+ import { isIPv4 as isIPv44 } from "net";
10768
10860
 
10769
10861
  // src/transport/dtls.ts
10770
10862
  import { Certificate as Certificate3, PrivateKey as PrivateKey2 } from "@fidm/x509";
@@ -11698,11 +11790,9 @@ var RTCIceParameters = class {
11698
11790
 
11699
11791
  // src/transport/sctp.ts
11700
11792
  import { randomUUID as randomUUID8 } from "crypto";
11701
- import { jspack as jspack5 } from "@shinyoshiaki/jspack";
11702
11793
 
11703
11794
  // ../sctp/src/sctp.ts
11704
11795
  import { createHmac as createHmac5, randomBytes as randomBytes8 } from "crypto";
11705
- import { jspack as jspack4 } from "@shinyoshiaki/jspack";
11706
11796
 
11707
11797
  // ../sctp/src/chunk.ts
11708
11798
  var Chunk = class _Chunk {
@@ -12155,7 +12245,6 @@ function createEventsFromList(list) {
12155
12245
  }
12156
12246
 
12157
12247
  // ../sctp/src/param.ts
12158
- import { jspack as jspack3 } from "@shinyoshiaki/jspack";
12159
12248
  var OutgoingSSNResetRequestParam = class _OutgoingSSNResetRequestParam {
12160
12249
  // Outgoing SSN Reset Request Parameter
12161
12250
  constructor(requestSequence, responseSequence, lastTsn, streams) {
@@ -12169,26 +12258,26 @@ var OutgoingSSNResetRequestParam = class _OutgoingSSNResetRequestParam {
12169
12258
  return _OutgoingSSNResetRequestParam.type;
12170
12259
  }
12171
12260
  get bytes() {
12172
- const data = Buffer.from(
12173
- jspack3.Pack("!LLL", [
12174
- this.requestSequence,
12175
- this.responseSequence,
12176
- this.lastTsn
12177
- ])
12178
- );
12261
+ const data = Buffer.allocUnsafe(12);
12262
+ data.writeUInt32BE(this.requestSequence, 0);
12263
+ data.writeUInt32BE(this.responseSequence, 4);
12264
+ data.writeUInt32BE(this.lastTsn, 8);
12179
12265
  return Buffer.concat([
12180
12266
  data,
12181
- ...this.streams.map((stream) => Buffer.from(jspack3.Pack("!H", [stream])))
12267
+ ...this.streams.map((stream) => {
12268
+ const buf = Buffer.allocUnsafe(2);
12269
+ buf.writeUInt16BE(stream, 0);
12270
+ return buf;
12271
+ })
12182
12272
  ]);
12183
12273
  }
12184
12274
  static parse(data) {
12185
- const [requestSequence, responseSequence, lastTsn] = jspack3.Unpack(
12186
- "!LLL",
12187
- data
12188
- );
12275
+ const requestSequence = data.readUInt32BE(0);
12276
+ const responseSequence = data.readUInt32BE(4);
12277
+ const lastTsn = data.readUInt32BE(8);
12189
12278
  const stream = [];
12190
12279
  for (let pos = 12; pos < data.length; pos += 2) {
12191
- stream.push(jspack3.Unpack("!H", data.slice(pos))[0]);
12280
+ stream.push(data.readUInt16BE(pos));
12192
12281
  }
12193
12282
  return new _OutgoingSSNResetRequestParam(
12194
12283
  requestSequence,
@@ -12209,12 +12298,15 @@ var StreamAddOutgoingParam = class _StreamAddOutgoingParam {
12209
12298
  return _StreamAddOutgoingParam.type;
12210
12299
  }
12211
12300
  get bytes() {
12212
- return Buffer.from(
12213
- jspack3.Pack("!LHH", [this.requestSequence, this.newStreams, 0])
12214
- );
12301
+ const buf = Buffer.allocUnsafe(8);
12302
+ buf.writeUInt32BE(this.requestSequence, 0);
12303
+ buf.writeUInt16BE(this.newStreams, 4);
12304
+ buf.writeUInt16BE(0, 6);
12305
+ return buf;
12215
12306
  }
12216
12307
  static parse(data) {
12217
- const [requestSequence, newStreams] = jspack3.Unpack("!LHH", data);
12308
+ const requestSequence = data.readUInt32BE(0);
12309
+ const newStreams = data.readUInt16BE(4);
12218
12310
  return new _StreamAddOutgoingParam(requestSequence, newStreams);
12219
12311
  }
12220
12312
  };
@@ -12233,12 +12325,14 @@ var ReconfigResponseParam = class _ReconfigResponseParam {
12233
12325
  return _ReconfigResponseParam.type;
12234
12326
  }
12235
12327
  get bytes() {
12236
- return Buffer.from(
12237
- jspack3.Pack("!LL", [this.responseSequence, this.result])
12238
- );
12328
+ const buf = Buffer.allocUnsafe(8);
12329
+ buf.writeUInt32BE(this.responseSequence, 0);
12330
+ buf.writeUInt32BE(this.result, 4);
12331
+ return buf;
12239
12332
  }
12240
12333
  static parse(data) {
12241
- const [requestSequence, result] = jspack3.Unpack("!LL", data);
12334
+ const requestSequence = data.readUInt32BE(0);
12335
+ const result = data.readUInt32BE(4);
12242
12336
  return new _ReconfigResponseParam(requestSequence, result);
12243
12337
  }
12244
12338
  };
@@ -12507,8 +12601,10 @@ var SCTP = class _SCTP {
12507
12601
  ack.inboundStreams = this._inboundStreamsCount;
12508
12602
  ack.initialTsn = this.localTsn;
12509
12603
  this.setExtensions(ack.params);
12510
- const time = Date.now() / 1e3;
12511
- let cookie = Buffer.from(jspack4.Pack("!L", [time]));
12604
+ const time = Math.floor(Date.now() / 1e3);
12605
+ const cookieTime = Buffer.allocUnsafe(4);
12606
+ cookieTime.writeUInt32BE(time, 0);
12607
+ let cookie = cookieTime;
12512
12608
  cookie = Buffer.concat([
12513
12609
  cookie,
12514
12610
  createHmac5("sha1", this.hmacKey).update(cookie).digest()
@@ -12599,8 +12695,8 @@ var SCTP = class _SCTP {
12599
12695
  log30("x State cookie is invalid");
12600
12696
  return;
12601
12697
  }
12602
- const now = Date.now() / 1e3;
12603
- const stamp = jspack4.Unpack("!L", cookie)[0];
12698
+ const now = Math.floor(Date.now() / 1e3);
12699
+ const stamp = cookie.readUInt32BE(0);
12604
12700
  if (stamp < now - COOKIE_LIFETIME || stamp > now) {
12605
12701
  const error = new ErrorChunk(0, void 0);
12606
12702
  error.params.push([
@@ -13230,10 +13326,9 @@ var SCTP = class _SCTP {
13230
13326
  if (this.associationState !== 4 /* ESTABLISHED */) return;
13231
13327
  if (this.flightSize === 0 && this.outboundQueue.length === 0) {
13232
13328
  const heartbeat = new HeartbeatChunk();
13233
- heartbeat.params.push([
13234
- 1,
13235
- Buffer.from(jspack4.Pack("!L", [Math.floor(Date.now() / 1e3)]))
13236
- ]);
13329
+ const heartbeatTime = Buffer.allocUnsafe(4);
13330
+ heartbeatTime.writeUInt32BE(Math.floor(Date.now() / 1e3), 0);
13331
+ heartbeat.params.push([1, heartbeatTime]);
13237
13332
  await this.sendChunk(heartbeat).catch((err5) => {
13238
13333
  log30("send heartbeat failed", err5.message);
13239
13334
  });
@@ -13599,14 +13694,10 @@ var RTCSctpTransport = class _RTCSctpTransport {
13599
13694
  return;
13600
13695
  }
13601
13696
  if (!Object.keys(this.dataChannels).includes(streamId.toString())) {
13602
- const [
13603
- ,
13604
- channelType,
13605
- ,
13606
- reliability,
13607
- labelLength,
13608
- protocolLength
13609
- ] = jspack5.Unpack("!BBHLHH", data);
13697
+ const channelType = data.readUInt8(1);
13698
+ const reliability = data.readUInt32BE(4);
13699
+ const labelLength = data.readUInt16BE(8);
13700
+ const protocolLength = data.readUInt16BE(10);
13610
13701
  let pos = 12;
13611
13702
  const label = data.slice(pos, pos + labelLength).toString("utf8");
13612
13703
  pos += labelLength;
@@ -13637,11 +13728,9 @@ var RTCSctpTransport = class _RTCSctpTransport {
13637
13728
  log31("datachannel already opened", "retransmit ack");
13638
13729
  }
13639
13730
  const channel = this.dataChannels[streamId];
13640
- this.dataChannelQueue.push([
13641
- channel,
13642
- WEBRTC_DCEP,
13643
- Buffer.from(jspack5.Pack("!B", [DATA_CHANNEL_ACK]))
13644
- ]);
13731
+ const ack = Buffer.allocUnsafe(1);
13732
+ ack.writeUInt8(DATA_CHANNEL_ACK, 0);
13733
+ this.dataChannelQueue.push([channel, WEBRTC_DCEP, ack]);
13645
13734
  await this.dataChannelFlush();
13646
13735
  }
13647
13736
  break;
@@ -13716,16 +13805,15 @@ var RTCSctpTransport = class _RTCSctpTransport {
13716
13805
  channelType = 2;
13717
13806
  reliability = channel.maxPacketLifeTime;
13718
13807
  }
13719
- const data = jspack5.Pack("!BBHLHH", [
13720
- DATA_CHANNEL_OPEN,
13721
- channelType,
13722
- priority,
13723
- reliability,
13724
- channel.label.length,
13725
- channel.protocol.length
13726
- ]);
13808
+ const data = Buffer.allocUnsafe(12);
13809
+ data.writeUInt8(DATA_CHANNEL_OPEN, 0);
13810
+ data.writeUInt8(channelType, 1);
13811
+ data.writeUInt16BE(priority, 2);
13812
+ data.writeUInt32BE(reliability, 4);
13813
+ data.writeUInt16BE(channel.label.length, 8);
13814
+ data.writeUInt16BE(channel.protocol.length, 10);
13727
13815
  const send = Buffer.concat([
13728
- Buffer.from(data),
13816
+ data,
13729
13817
  Buffer.from(channel.label, "utf8"),
13730
13818
  Buffer.from(channel.protocol, "utf8")
13731
13819
  ]);
@@ -14332,7 +14420,7 @@ function ipAddressFromSdp(sdp) {
14332
14420
  return m[2];
14333
14421
  }
14334
14422
  function ipAddressToSdp(addr) {
14335
- const version = isIPv43(addr) ? 4 : 6;
14423
+ const version = isIPv44(addr) ? 4 : 6;
14336
14424
  return `IN IP${version} ${addr}`;
14337
14425
  }
14338
14426
  function candidateToSdp(c) {
@@ -14422,7 +14510,7 @@ var RTCSessionDescription = class {
14422
14510
  };
14423
14511
  function addSDPHeader(type, description) {
14424
14512
  const username = "-";
14425
- const sessionId = new Int643.Uint64BE(randomBytes9(64)).toString().slice(0, 8);
14513
+ const sessionId = randomBytes9(8).readBigUInt64BE(0).toString().slice(0, 8);
14426
14514
  const sessionVersion = 0;
14427
14515
  description.origin = `${username} ${sessionId} ${sessionVersion} IN IP4 0.0.0.0`;
14428
14516
  description.msidSemantic.push(new GroupDescription("WMS", ["*"]));
@@ -14977,7 +15065,6 @@ var RtpRouter = class {
14977
15065
 
14978
15066
  // src/media/rtpSender.ts
14979
15067
  import { randomBytes as randomBytes10 } from "crypto";
14980
- import { jspack as jspack6 } from "@shinyoshiaki/jspack";
14981
15068
  import { randomUUID as randomUUID10 } from "crypto";
14982
15069
  import { setTimeout as setTimeout9 } from "timers/promises";
14983
15070
 
@@ -15140,8 +15227,8 @@ var RTCRtpSender = class {
15140
15227
  }
15141
15228
  type = "sender";
15142
15229
  kind;
15143
- ssrc = jspack6.Unpack("!L", randomBytes10(4))[0];
15144
- rtxSsrc = jspack6.Unpack("!L", randomBytes10(4))[0];
15230
+ ssrc = randomBytes10(4).readUInt32BE(0);
15231
+ rtxSsrc = randomBytes10(4).readUInt32BE(0);
15145
15232
  trackId = randomUUID10().toString();
15146
15233
  onReady = new Event2();
15147
15234
  onRtcp = new Event2();