@eleven-am/pondsocket 0.1.195 → 0.1.197
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.
- package/package.json +1 -1
- package/server/server.js +28 -29
- package/types.d.ts +1 -0
package/package.json
CHANGED
package/server/server.js
CHANGED
|
@@ -19,7 +19,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
19
19
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
20
20
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
21
21
|
};
|
|
22
|
-
var _PondSocket_instances, _PondSocket_exclusiveServer, _PondSocket_server, _PondSocket_socketServer, _PondSocket_redisClient, _PondSocket_middleware, _PondSocket_manageHeartbeat, _PondSocket_init,
|
|
22
|
+
var _PondSocket_instances, _PondSocket_exclusiveServer, _PondSocket_server, _PondSocket_socketServer, _PondSocket_redisClient, _PondSocket_middleware, _PondSocket_manageHeartbeat, _PondSocket_init, _PondSocket_getCookies;
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
24
|
exports.PondSocket = void 0;
|
|
25
25
|
const http_1 = require("http");
|
|
@@ -77,6 +77,32 @@ class PondSocket {
|
|
|
77
77
|
});
|
|
78
78
|
return new endpoint_1.Endpoint(endpoint);
|
|
79
79
|
}
|
|
80
|
+
handleUpgrade(req, socket, head) {
|
|
81
|
+
const clientId = req.headers['sec-websocket-key'];
|
|
82
|
+
const request = {
|
|
83
|
+
id: clientId,
|
|
84
|
+
headers: req.headers,
|
|
85
|
+
address: req.url || '',
|
|
86
|
+
};
|
|
87
|
+
const params = {
|
|
88
|
+
head,
|
|
89
|
+
socket,
|
|
90
|
+
request: req,
|
|
91
|
+
requestId: (0, pondsocket_common_1.uuid)(),
|
|
92
|
+
};
|
|
93
|
+
__classPrivateFieldGet(this, _PondSocket_middleware, "f").run(request, params, (error) => {
|
|
94
|
+
if (error) {
|
|
95
|
+
const code = (error === null || error === void 0 ? void 0 : error.statusCode) || 400;
|
|
96
|
+
const message = (error === null || error === void 0 ? void 0 : error.message) || 'Unauthorized connection';
|
|
97
|
+
socket.write(`HTTP/1.1 ${code} ${message}\r\n\r\n`);
|
|
98
|
+
socket.destroy();
|
|
99
|
+
}
|
|
100
|
+
else if (__classPrivateFieldGet(this, _PondSocket_exclusiveServer, "f")) {
|
|
101
|
+
socket.write('HTTP/1.1 404 Not Found\r\n\r\n');
|
|
102
|
+
socket.destroy();
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
80
106
|
}
|
|
81
107
|
exports.PondSocket = PondSocket;
|
|
82
108
|
_PondSocket_exclusiveServer = new WeakMap(), _PondSocket_server = new WeakMap(), _PondSocket_socketServer = new WeakMap(), _PondSocket_redisClient = new WeakMap(), _PondSocket_middleware = new WeakMap(), _PondSocket_instances = new WeakSet(), _PondSocket_manageHeartbeat = function _PondSocket_manageHeartbeat() {
|
|
@@ -107,34 +133,7 @@ _PondSocket_exclusiveServer = new WeakMap(), _PondSocket_server = new WeakMap(),
|
|
|
107
133
|
clearInterval(timeout);
|
|
108
134
|
yield ((_a = __classPrivateFieldGet(this, _PondSocket_redisClient, "f")) === null || _a === void 0 ? void 0 : _a.shutdown());
|
|
109
135
|
}));
|
|
110
|
-
__classPrivateFieldGet(this, _PondSocket_server, "f").on('upgrade', (
|
|
111
|
-
__classPrivateFieldGet(this, _PondSocket_instances, "m", _PondSocket_handleUpgrade).call(this, req, socket, head);
|
|
112
|
-
});
|
|
113
|
-
}, _PondSocket_handleUpgrade = function _PondSocket_handleUpgrade(req, socket, head) {
|
|
114
|
-
const clientId = req.headers['sec-websocket-key'];
|
|
115
|
-
const request = {
|
|
116
|
-
id: clientId,
|
|
117
|
-
headers: req.headers,
|
|
118
|
-
address: req.url || '',
|
|
119
|
-
};
|
|
120
|
-
const params = {
|
|
121
|
-
head,
|
|
122
|
-
socket,
|
|
123
|
-
request: req,
|
|
124
|
-
requestId: (0, pondsocket_common_1.uuid)(),
|
|
125
|
-
};
|
|
126
|
-
__classPrivateFieldGet(this, _PondSocket_middleware, "f").run(request, params, (error) => {
|
|
127
|
-
if (error) {
|
|
128
|
-
const code = (error === null || error === void 0 ? void 0 : error.statusCode) || 400;
|
|
129
|
-
const message = (error === null || error === void 0 ? void 0 : error.message) || 'Unauthorized connection';
|
|
130
|
-
socket.write(`HTTP/1.1 ${code} ${message}\r\n\r\n`);
|
|
131
|
-
socket.destroy();
|
|
132
|
-
}
|
|
133
|
-
else if (__classPrivateFieldGet(this, _PondSocket_exclusiveServer, "f")) {
|
|
134
|
-
socket.write('HTTP/1.1 404 Not Found\r\n\r\n');
|
|
135
|
-
socket.destroy();
|
|
136
|
-
}
|
|
137
|
-
});
|
|
136
|
+
__classPrivateFieldGet(this, _PondSocket_server, "f").on('upgrade', this.handleUpgrade.bind(this));
|
|
138
137
|
}, _PondSocket_getCookies = function _PondSocket_getCookies(headers) {
|
|
139
138
|
const cookieHeader = headers.cookie;
|
|
140
139
|
if (!cookieHeader) {
|
package/types.d.ts
CHANGED