mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
* Fix event data property names * Fix server options protocolVersion is optional (and defaults to 2).
46 lines
1.6 KiB
TypeScript
46 lines
1.6 KiB
TypeScript
// Adapted from README
|
|
|
|
import http = require('http');
|
|
import socketClusterServer = require('socketcluster-server');
|
|
|
|
const httpServer = http.createServer();
|
|
let agServer = socketClusterServer.attach(httpServer);
|
|
|
|
(async () => {
|
|
// Handle new inbound sockets.
|
|
// tslint:disable-next-line: await-promise Bug in tslint: https://github.com/palantir/tslint/issues/3997
|
|
for await (const { socket } of agServer.listener('connection')) {
|
|
(async () => {
|
|
// Set up a loop to handle and respond to RPCs for a procedure.
|
|
// tslint:disable-next-line: await-promise Bug in tslint: https://github.com/palantir/tslint/issues/3997
|
|
for await (const req of socket.procedure('customProc')) {
|
|
if (req.data.bad) {
|
|
const error = new Error('Server failed to execute the procedure');
|
|
error.name = 'BadCustomError';
|
|
req.error(error);
|
|
} else {
|
|
req.end('Success');
|
|
}
|
|
}
|
|
})();
|
|
|
|
(async () => {
|
|
// Set up a loop to handle remote transmitted events.
|
|
// tslint:disable-next-line: await-promise Bug in tslint: https://github.com/palantir/tslint/issues/3997
|
|
for await (const data of socket.receiver('customRemoteEvent')) {
|
|
// $ExpectType any
|
|
data;
|
|
}
|
|
})();
|
|
}
|
|
})();
|
|
|
|
httpServer.listen(8000);
|
|
|
|
agServer = socketClusterServer.attach(httpServer, {
|
|
protocolVersion: 1,
|
|
path: '/socketcluster/',
|
|
});
|
|
|
|
agServer = socketClusterServer.attach(httpServer, {});
|