@lakutata/webrtc 3.1.5 → 3.1.6

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.
@@ -449,7 +449,9 @@ class SFUWorkers {
449
449
  //Running once it says so: a thread failing to start is not started again
450
450
  slot.ran = false;
451
451
  const resourceLimits = this.#host.resourceLimits;
452
- const worker = new node_worker_threads_1.Worker(SFUWorkerCode_js_1.sfuWorkerCode, { eval: true, workerData: this.#data[slot.index], ...resourceLimits ? { resourceLimits: resourceLimits } : {} });
452
+ //Without the options of the command line of the process, which a worker inherits: with --input-type=module, its code
453
+ //(CommonJS) would run as an ES module
454
+ const worker = new node_worker_threads_1.Worker(SFUWorkerCode_js_1.sfuWorkerCode, { eval: true, execArgv: [], workerData: this.#data[slot.index], ...resourceLimits ? { resourceLimits: resourceLimits } : {} });
453
455
  slot.worker = worker;
454
456
  slot.channel = new SFUWorkerChannel_js_1.SFUWorkerChannel(worker, (message) => this.#handle(slot, message));
455
457
  slot.ready = new Promise((resolve, reject) => {
@@ -165,7 +165,9 @@ class TURNWorkers {
165
165
  port: this.#port,
166
166
  ...data.options.tls && this.#tlsPort !== undefined ? { tls: { ...data.options.tls, port: this.#tlsPort } } : {}
167
167
  };
168
- const worker = new node_worker_threads_1.Worker(TURNWorkerCode_js_1.turnWorkerCode, { eval: true, workerData: { ...data, options: options } });
168
+ //Without the options of the command line of the process, which a worker inherits: with --input-type=module, its code
169
+ //(CommonJS) would run as an ES module
170
+ const worker = new node_worker_threads_1.Worker(TURNWorkerCode_js_1.turnWorkerCode, { eval: true, execArgv: [], workerData: { ...data, options: options } });
169
171
  slot.worker = worker;
170
172
  if ((0, log_js_1.hasDebugHandler)())
171
173
  worker.postMessage({ type: 'debug', enabled: true });
@@ -40,8 +40,13 @@ export class DnsLookup {
40
40
  constructor() {
41
41
  this.cache = new Map();
42
42
  const lookupWorkerFunction = () => {
43
- const worker_thread = global.require('worker_threads');
44
- const { lookup } = global.require('dns');
43
+ //The modules of Node.js: process.getBuiltinModule where there is one (Bun has no global.require), else the
44
+ //require of the script (Node.js before 20.16). No require is named in the function, whose text runs in the
45
+ //worker: a bundler would rewrite it
46
+ //node-compat: process.getBuiltinModule (checked first, global.require where it is missing)
47
+ const load = (id) => typeof process.getBuiltinModule === 'function' ? process.getBuiltinModule(id) : global.require(id);
48
+ const worker_thread = load('worker_threads');
49
+ const { lookup } = load('dns');
45
50
  const dnsLookup = (host) => lookup(host, (err, address, family) => {
46
51
  const res = {
47
52
  err: err?.message,
@@ -59,7 +64,10 @@ export class DnsLookup {
59
64
  };
60
65
  const lookupEval = `(${lookupWorkerFunction})()`;
61
66
  this.thread = new worker_thread.Worker(lookupEval, {
62
- eval: true
67
+ eval: true,
68
+ //Without the options of the command line of the process, which a worker inherits: with --input-type=module, its code
69
+ //(CommonJS) would run as an ES module
70
+ execArgv: []
63
71
  });
64
72
  this.thread.setMaxListeners(100);
65
73
  }
@@ -169,6 +169,9 @@ let PeerThreads = class PeerThreads extends Component {
169
169
  return slot.ready;
170
170
  const worker = new Worker(peerWorkerCode, {
171
171
  eval: true,
172
+ //Without the options of the command line of the process, which a worker inherits: with --input-type=module, its code
173
+ //(CommonJS) would run as an ES module
174
+ execArgv: [],
172
175
  workerData: { thread: slot.index },
173
176
  ...this.resourceLimits ? { resourceLimits: this.resourceLimits } : {}
174
177
  });