socket-function 0.8.37 → 0.8.38

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.
@@ -64,12 +64,18 @@ export async function startSocketServer(
64
64
  });
65
65
 
66
66
  httpsServer.on("connection", socket => {
67
- console.log("Client connection established");
67
+ if (!SocketFunction.silent) {
68
+ console.log("Client connection established");
69
+ }
68
70
  socket.on("error", e => {
69
- console.log(`Client socket error ${e.message}`);
71
+ if (!SocketFunction.silent) {
72
+ console.log(`Client socket error ${e.message}`);
73
+ }
70
74
  });
71
75
  socket.on("close", () => {
72
- console.log("Client socket closed");
76
+ if (!SocketFunction.silent) {
77
+ console.log("Client socket closed");
78
+ }
73
79
  });
74
80
  });
75
81
  httpsServer.on("error", e => {
@@ -83,7 +89,9 @@ export async function startSocketServer(
83
89
 
84
90
  httpsServer.on("upgrade", (request, socket, upgradeHead) => {
85
91
  socket.on("error", e => {
86
- console.log(`Client socket error ${e.message}`);
92
+ if (!SocketFunction.silent) {
93
+ console.log(`Client socket error ${e.message}`);
94
+ }
87
95
  });
88
96
 
89
97
  let originHeader = request.headers["origin"];
@@ -153,7 +161,9 @@ export async function startSocketServer(
153
161
  } else {
154
162
  let data = parseTLSHello(buffer);
155
163
  let sni = data.extensions.filter(x => x.type === SNIType).flatMap(x => parseSNIExtension(x.data))[0];
156
- console.log(`Received TCP connection with SNI ${JSON.stringify(sni)}`);
164
+ if (!SocketFunction.silent) {
165
+ console.log(`Received TCP connection with SNI ${JSON.stringify(sni)}`);
166
+ }
157
167
  server = sniServers.get(sni) || mainHTTPSServer;
158
168
  }
159
169
 
@@ -176,10 +186,9 @@ export async function startSocketServer(
176
186
  });
177
187
  });
178
188
 
179
-
180
- let host = config.ip ?? "127.0.0.1";
181
- if (config.public) {
182
- host = "0.0.0.0";
189
+ let host = config.public ? "0.0.0.0" : "127.0.0.1";
190
+ if (config.ip) {
191
+ host = config.ip;
183
192
  }
184
193
 
185
194
  let port = config.port;
@@ -203,14 +212,18 @@ export async function startSocketServer(
203
212
  }
204
213
  }
205
214
 
206
- console.log(`Trying to listening on ${host}:${port}`);
215
+ if (!SocketFunction.silent) {
216
+ console.log(`Trying to listening on ${host}:${port}`);
217
+ }
207
218
  realServer.listen(port, host);
208
219
 
209
220
  await listenPromise;
210
221
 
211
222
  port = (realServer.address() as net.AddressInfo).port;
212
223
  let nodeId = getNodeId(getCommonName(config.cert), port);
213
- console.log(`Started Listening on ${nodeId}`);
224
+ if (!SocketFunction.silent) {
225
+ console.log(`Started Listening on ${nodeId}`);
226
+ }
214
227
 
215
228
  return nodeId;
216
229
  }
@@ -5,6 +5,7 @@ import { SenderInterface } from "./CallFactory";
5
5
  import { getTrustedCertificates } from "./certStore";
6
6
  import { getNodeIdLocation } from "./nodeCache";
7
7
  import debugbreak from "debugbreak";
8
+ import { SocketFunction } from "../SocketFunction";
8
9
 
9
10
 
10
11
  export function getTLSSocket(webSocket: ws.WebSocket) {
@@ -22,7 +23,9 @@ export function createWebsocketFactory(): (nodeId: string) => SenderInterface {
22
23
  if (!location) throw new Error(`Cannot connect to ${nodeId}, no address known`);
23
24
  let { address, port } = location;
24
25
 
25
- console.log(`Connecting to ${address}:${port}`);
26
+ if (!SocketFunction.silent) {
27
+ console.log(`Connecting to ${address}:${port}`);
28
+ }
26
29
  return new WebSocket(`wss://${address}:${port}`);
27
30
  };
28
31
  } else {
@@ -31,7 +34,9 @@ export function createWebsocketFactory(): (nodeId: string) => SenderInterface {
31
34
  if (!location) throw new Error(`Cannot connect to ${nodeId}, no address known`);
32
35
  let { address, port } = location;
33
36
 
34
- console.log(`Connecting to ${address}:${port}`);
37
+ if (!SocketFunction.silent) {
38
+ console.log(`Connecting to ${address}:${port}`);
39
+ }
35
40
  let webSocket = new ws.WebSocket(`wss://${address}:${port}`, {
36
41
  ca: tls.rootCertificates.concat(getTrustedCertificates()),
37
42
  });