Skip to content

Commit ace92cc

Browse files
committed
Add support for unix domain sockets
1 parent 508841a commit ace92cc

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

lib/clientsocket.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ function AGClientSocket(socketOptions) {
2626
let defaultOptions = {
2727
path: '/socketcluster/',
2828
secure: false,
29+
protocolScheme: null,
30+
socketPath: null,
2931
autoConnect: true,
3032
autoReconnect: true,
3133
autoSubscribeOnConnect: true,

lib/transport.js

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,12 @@ AGTransport.CLOSED = AGTransport.prototype.CLOSED = 'closed';
129129

130130
AGTransport.prototype.uri = function () {
131131
let query = this.options.query || {};
132-
let schema = this.options.secure ? 'wss' : 'ws';
132+
let scheme;
133+
if (this.options.protocolScheme == null) {
134+
scheme = this.options.secure ? 'wss' : 'ws';
135+
} else {
136+
scheme = this.options.protocolScheme;
137+
}
133138

134139
if (this.options.timestampRequests) {
135140
query[this.options.timestampParam] = (new Date()).getTime();
@@ -142,19 +147,25 @@ AGTransport.prototype.uri = function () {
142147
}
143148

144149
let host;
145-
if (this.options.host) {
146-
host = this.options.host;
147-
} else {
148-
let port = '';
150+
let path;
151+
if (this.options.socketPath == null) {
152+
if (this.options.host) {
153+
host = this.options.host;
154+
} else {
155+
let port = '';
149156

150-
if (this.options.port && ((schema === 'wss' && this.options.port !== 443)
151-
|| (schema === 'ws' && this.options.port !== 80))) {
152-
port = ':' + this.options.port;
157+
if (this.options.port && ((scheme === 'wss' && this.options.port !== 443)
158+
|| (scheme === 'ws' && this.options.port !== 80))) {
159+
port = ':' + this.options.port;
160+
}
161+
host = this.options.hostname + port;
153162
}
154-
host = this.options.hostname + port;
163+
path = this.options.path;
164+
} else {
165+
host = this.options.socketPath;
166+
path = `:${this.options.path}`;
155167
}
156-
157-
return schema + '://' + host + this.options.path + query;
168+
return scheme + '://' + host + path + query;
158169
};
159170

160171
AGTransport.prototype._onOpen = async function () {

0 commit comments

Comments
 (0)