@apocaliss92/nodelink-js 0.6.0 → 0.6.2

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.
@@ -2363,6 +2363,46 @@ function buildRtspUrl(params) {
2363
2363
  }
2364
2364
 
2365
2365
  // src/protocol/xml.ts
2366
+ var xmlTextReCache = /* @__PURE__ */ new Map();
2367
+ function xmlTextRe(tag) {
2368
+ let re = xmlTextReCache.get(tag);
2369
+ if (re === void 0) {
2370
+ re = new RegExp(`<${tag}>([^<]*)</${tag}>`);
2371
+ xmlTextReCache.set(tag, re);
2372
+ }
2373
+ return re;
2374
+ }
2375
+ var xmlTagReCache = /* @__PURE__ */ new Map();
2376
+ function xmlTagRe(tag) {
2377
+ let re = xmlTagReCache.get(tag);
2378
+ if (re === void 0) {
2379
+ re = new RegExp(`<${tag}>[^<]*</${tag}>`);
2380
+ xmlTagReCache.set(tag, re);
2381
+ }
2382
+ return re;
2383
+ }
2384
+ var xmlNestedReCache = /* @__PURE__ */ new Map();
2385
+ function xmlNestedRe(parent, child) {
2386
+ const key = `${parent}\0${child}`;
2387
+ let re = xmlNestedReCache.get(key);
2388
+ if (re === void 0) {
2389
+ re = new RegExp(
2390
+ `(<${parent}[^>]*>[\\s\\S]*?<${child}>)[^<]*(</${child}>[\\s\\S]*?</${parent}>)`
2391
+ );
2392
+ xmlNestedReCache.set(key, re);
2393
+ }
2394
+ return re;
2395
+ }
2396
+ var GOP_BLOCK_RE = /(<gop[^>]*>)([\s\S]*?)(<\/gop>)/;
2397
+ var xmlStreamBlockReCache = /* @__PURE__ */ new Map();
2398
+ function xmlStreamBlockRe(streamTag) {
2399
+ let re = xmlStreamBlockReCache.get(streamTag);
2400
+ if (re === void 0) {
2401
+ re = new RegExp(`(<${streamTag}[^>]*>)([\\s\\S]*?)(</${streamTag}>)`);
2402
+ xmlStreamBlockReCache.set(streamTag, re);
2403
+ }
2404
+ return re;
2405
+ }
2366
2406
  function xmlEscape(text) {
2367
2407
  if (text === void 0 || text === null || typeof text !== "string") {
2368
2408
  const error = new Error(
@@ -2483,8 +2523,7 @@ function buildPreviewStopXmlV11(params) {
2483
2523
  </body>`;
2484
2524
  }
2485
2525
  function getXmlText(xml, tagName) {
2486
- const re = new RegExp(`<${tagName}>([^<]*)</${tagName}>`);
2487
- const m = re.exec(xml);
2526
+ const m = xmlTextRe(tagName).exec(xml);
2488
2527
  return m?.[1];
2489
2528
  }
2490
2529
  function buildPtzControlXml(channelId, command, speed) {
@@ -2589,13 +2628,12 @@ ${xml}`;
2589
2628
  function applyXmlTagPatch(xml, tag, value) {
2590
2629
  if (value === void 0) return xml;
2591
2630
  const v = typeof value === "boolean" ? value ? 1 : 0 : value;
2592
- const re = new RegExp(`<${tag}>[^<]*</${tag}>`);
2593
- return xml.replace(re, `<${tag}>${v}</${tag}>`);
2631
+ return xml.replace(xmlTagRe(tag), `<${tag}>${v}</${tag}>`);
2594
2632
  }
2595
2633
  function upsertXmlTag(xml, tag, value) {
2596
2634
  if (value === void 0) return xml;
2597
2635
  const v = typeof value === "boolean" ? value ? 1 : 0 : value;
2598
- const re = new RegExp(`<${tag}>[^<]*</${tag}>`);
2636
+ const re = xmlTagRe(tag);
2599
2637
  if (re.test(xml)) {
2600
2638
  return xml.replace(re, `<${tag}>${v}</${tag}>`);
2601
2639
  }
@@ -2604,16 +2642,11 @@ function upsertXmlTag(xml, tag, value) {
2604
2642
  function patchNestedTag(xml, parent, child, value) {
2605
2643
  if (value === void 0) return xml;
2606
2644
  const v = typeof value === "boolean" ? value ? 1 : 0 : value;
2607
- const re = new RegExp(
2608
- `(<${parent}[^>]*>[\\s\\S]*?<${child}>)[^<]*(</${child}>[\\s\\S]*?</${parent}>)`
2609
- );
2610
- return xml.replace(re, `$1${v}$2`);
2645
+ return xml.replace(xmlNestedRe(parent, child), `$1${v}$2`);
2611
2646
  }
2612
2647
  function applyStreamPatch(xml, streamTag, patch) {
2613
2648
  if (!patch) return xml;
2614
- const re = new RegExp(
2615
- `(<${streamTag}[^>]*>)([\\s\\S]*?)(</${streamTag}>)`
2616
- );
2649
+ const re = xmlStreamBlockRe(streamTag);
2617
2650
  return xml.replace(re, (_match, open, body, close) => {
2618
2651
  let next = body;
2619
2652
  if (patch.audio !== void 0) {
@@ -2643,10 +2676,9 @@ function applyStreamPatch(xml, streamTag, patch) {
2643
2676
  next = upsertXmlTag(next, "encoderProfile", patch.encoderProfile);
2644
2677
  }
2645
2678
  if (patch.gop !== void 0) {
2646
- const gopBlockRe = /(<gop[^>]*>)([\s\S]*?)(<\/gop>)/;
2647
- if (gopBlockRe.test(next)) {
2679
+ if (GOP_BLOCK_RE.test(next)) {
2648
2680
  next = next.replace(
2649
- gopBlockRe,
2681
+ GOP_BLOCK_RE,
2650
2682
  (_m, gOpen, gBody, gClose) => `${gOpen}${applyXmlTagPatch(gBody, "cur", patch.gop)}${gClose}`
2651
2683
  );
2652
2684
  } else {
@@ -5586,4 +5618,4 @@ export {
5586
5618
  parseRecordingFileName,
5587
5619
  ReolinkCgiApi
5588
5620
  };
5589
- //# sourceMappingURL=chunk-XDVBNZGR.js.map
5621
+ //# sourceMappingURL=chunk-IQVVVSXO.js.map