@dainprotocol/tunnel 1.1.17 → 1.1.18

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.
@@ -233,6 +233,8 @@ class DainTunnel extends events_1.EventEmitter {
233
233
  }
234
234
  handleSSEConnection(message) {
235
235
  var _a;
236
+ const startTime = Date.now();
237
+ console.log(`[SSE E2E] Client: Establishing SSE connection ${message.id} to localhost:${this.port}${message.path}`);
236
238
  try {
237
239
  const options = {
238
240
  hostname: 'localhost',
@@ -245,16 +247,19 @@ class DainTunnel extends events_1.EventEmitter {
245
247
  const req = http_1.default.request(options, (res) => {
246
248
  var _a;
247
249
  if (res.statusCode !== 200) {
250
+ console.log(`[SSE E2E] Client: Service returned status ${res.statusCode} for ${message.id}`);
248
251
  res.resume();
249
252
  if (((_a = this.ws) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.OPEN) {
250
253
  this.ws.send(JSON.stringify({ type: 'sse', id: message.id, event: 'error', data: `Status ${res.statusCode}` }));
251
254
  }
252
255
  return;
253
256
  }
257
+ console.log(`[SSE E2E] Client: Service accepted SSE connection ${message.id}, streaming started`);
254
258
  const socket = res.socket || res.connection;
255
259
  if (socket === null || socket === void 0 ? void 0 : socket.setNoDelay)
256
260
  socket.setNoDelay(true);
257
261
  let buffer = '';
262
+ let eventCount = 0;
258
263
  res.on('data', (chunk) => {
259
264
  var _a;
260
265
  buffer += chunk.toString();
@@ -271,13 +276,20 @@ class DainTunnel extends events_1.EventEmitter {
271
276
  }
272
277
  if (data.endsWith('\n'))
273
278
  data = data.slice(0, -1);
279
+ eventCount++;
280
+ console.log(`[SSE E2E] Client: Received event #${eventCount} from service for ${message.id}: ${event} (${Date.now() - startTime}ms)`);
274
281
  if (((_a = this.ws) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.OPEN) {
275
282
  this.ws.send(JSON.stringify({ type: 'sse', id: message.id, event, data }));
283
+ console.log(`[SSE E2E] Client: Forwarded event to tunnel server for ${message.id}`);
284
+ }
285
+ else {
286
+ console.log(`[SSE E2E] Client: WebSocket closed, cannot forward event for ${message.id}`);
276
287
  }
277
288
  }
278
289
  });
279
290
  res.on('end', () => {
280
291
  var _a;
292
+ console.log(`[SSE E2E] Client: Service closed connection for ${message.id} after ${eventCount} events (${Date.now() - startTime}ms)`);
281
293
  if (((_a = this.ws) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.OPEN) {
282
294
  this.ws.send(JSON.stringify({ type: 'sse', id: message.id, event: 'close', data: 'Connection closed' }));
283
295
  }
@@ -285,6 +297,7 @@ class DainTunnel extends events_1.EventEmitter {
285
297
  });
286
298
  req.on('error', (error) => {
287
299
  var _a;
300
+ console.log(`[SSE E2E] Client: Request error for ${message.id}: ${error.message}`);
288
301
  if (((_a = this.ws) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.OPEN) {
289
302
  this.ws.send(JSON.stringify({ type: 'sse', id: message.id, event: 'error', data: error.message }));
290
303
  }
@@ -296,17 +309,23 @@ class DainTunnel extends events_1.EventEmitter {
296
309
  this.emit("sse_connection", { id: message.id, path: message.path });
297
310
  }
298
311
  catch (error) {
312
+ console.log(`[SSE E2E] Client: Exception for ${message.id}: ${error.message}`);
299
313
  if (((_a = this.ws) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.OPEN) {
300
314
  this.ws.send(JSON.stringify({ type: 'sse', id: message.id, event: 'error', data: error.message }));
301
315
  }
302
316
  }
303
317
  }
304
318
  handleSSEClose(message) {
319
+ console.log(`[SSE E2E] Client: Received close command from server for ${message.id}`);
305
320
  const client = this.sseClients.get(message.id);
306
321
  if (client) {
322
+ console.log(`[SSE E2E] Client: Destroying local service connection for ${message.id}`);
307
323
  client.destroy();
308
324
  this.sseClients.delete(message.id);
309
325
  }
326
+ else {
327
+ console.log(`[SSE E2E] Client: No active connection found for ${message.id} (already closed?)`);
328
+ }
310
329
  }
311
330
  forwardRequest(request) {
312
331
  return new Promise((resolve, reject) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dainprotocol/tunnel",
3
- "version": "1.1.17",
3
+ "version": "1.1.18",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "private": false,