@scrypted/server 0.0.83 → 0.0.87

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.

Potentially problematic release.


This version of @scrypted/server might be problematic. Click here for more details.

@@ -63,43 +63,19 @@ else {
63
63
  })
64
64
  }
65
65
 
66
- const debuggers = new Map<number, net.Socket[]>();
67
66
  const debugServer = net.createServer(async (socket) => {
68
67
  if (!workerInspectPort) {
69
68
  socket.destroy();
70
69
  return;
71
70
  }
72
71
 
73
- const entry = debuggers.get(workerInspectPort);
74
- if (!entry) {
75
- debuggers.set(workerInspectPort, [socket]);
76
- }
77
- else {
78
- entry.push(socket);
79
- }
80
-
81
72
  for (let i = 0; i < 10; i++) {
82
73
  try {
83
74
  const target = await doconnect();
84
75
  socket.pipe(target).pipe(socket);
85
76
  const destroy = () => {
86
- socket.end();
87
77
  socket.destroy();
88
- target.end();
89
78
  target.destroy();
90
-
91
- if (!entry) {
92
- const sockets = debuggers.get(workerInspectPort);
93
- if (!debuggers.delete(workerInspectPort))
94
- return;
95
- setTimeout(() => {
96
- if (debuggers.has(workerInspectPort))
97
- return;
98
- for (const s of sockets) {
99
- s.destroy();
100
- }
101
- }, 500)
102
- }
103
79
  }
104
80
  socket.on('error', destroy);
105
81
  target.on('error', destroy);
@@ -185,7 +161,7 @@ else {
185
161
 
186
162
  // legacy secure port 9443 is now in use by portainer.
187
163
  let shownLegacyPortAlert = false
188
- const legacySecure = https.createServer({ key: keys.serviceKey, cert: keys.certificate }, (req, res) => {
164
+ const legacySecure = https.createServer(mergedHttpsServerOptions, (req, res) => {
189
165
  if (!shownLegacyPortAlert) {
190
166
  const core = scrypted.findPluginDevice('@scrypted/core');
191
167
  if (core) {
@@ -273,8 +249,8 @@ else {
273
249
  console.log('Ports can be changed with environment variables.')
274
250
  console.log('https: $SCRYPTED_SECURE_PORT')
275
251
  console.log('http : $SCRYPTED_INSECURE_PORT')
276
- console.log('Certificate can be by providing tls.createSecureContext options')
277
- console.log('JSON file in the SCRYPTED_HTTPS_OPTIONS_FILE environment variable:');
252
+ console.log('Certificate can be modified via tls.createSecureContext options in')
253
+ console.log('JSON file located at SCRYPTED_HTTPS_OPTIONS_FILE environment variable:');
278
254
  console.log('export SCRYPTED_HTTPS_OPTIONS_FILE=/path/to/options.json');
279
255
  console.log('https://nodejs.org/api/tls.html#tlscreatesecurecontextoptions')
280
256
  console.log('#######################################################');
@@ -370,15 +346,22 @@ else {
370
346
  }
371
347
 
372
348
  const waitDebug = new Promise<void>((resolve, reject) => {
373
- setTimeout(() => reject(new Error('timed out waiting for debug session')), 10000);
349
+ setTimeout(() => reject(new Error('timed out waiting for debug session')), 30000);
374
350
  debugServer.on('connection', resolve);
375
351
  });
376
352
 
377
353
  workerInspectPort = Math.round(Math.random() * 10000) + 30000;
378
- const pluginHost = await scrypted.installPlugin(plugin, {
379
- waitDebug,
380
- inspectPort: workerInspectPort,
381
- });
354
+ try {
355
+ await scrypted.installPlugin(plugin, {
356
+ waitDebug,
357
+ inspectPort: workerInspectPort,
358
+ });
359
+ }
360
+ catch (e) {
361
+ res.status(500);
362
+ res.send(e.toString());
363
+ return
364
+ }
382
365
 
383
366
  res.send({
384
367
  workerInspectPort,
@@ -119,6 +119,14 @@ export class PluginComponent {
119
119
  }
120
120
 
121
121
  async getRemoteServicePort(pluginId: string, name: string): Promise<number> {
122
+ if (name === 'console') {
123
+ const consoleServer = await this.scrypted.plugins[pluginId].consoleServer;
124
+ return consoleServer.readPort;
125
+ }
126
+ if (name === 'console-writer') {
127
+ const consoleServer = await this.scrypted.plugins[pluginId].consoleServer;
128
+ return consoleServer.writePort;
129
+ }
122
130
  return this.scrypted.plugins[pluginId].remote.getServicePort(name);
123
131
  }
124
132
  }