MCPcopy
hub / github.com/socketio/socket.io / createServer

Function createServer

packages/socket.io-client/test/support/server.ts:4–169  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2import expect = require("expect.js");
3
4export function createServer() {
5 const server = new Server(3210, {
6 pingInterval: 2000,
7 connectionStateRecovery: {},
8 allowRequest: (req, callback) => {
9 // add a fixed delay to test the connection timeout on the client side
10 setTimeout(() => callback(null, true), 10);
11 },
12 });
13
14 server.of("/foo").on("connection", (socket) => {
15 socket.on("getId", (cb) => {
16 cb(socket.id);
17 });
18 });
19
20 server.of("/timeout_socket").on("connection", () => {
21 // register namespace
22 });
23
24 server.of("/valid").on("connection", () => {
25 // register namespace
26 });
27
28 server.of("/asd").on("connection", () => {
29 // register namespace
30 });
31
32 server.of("/abc").on("connection", (socket) => {
33 socket.emit("handshake", socket.handshake);
34 });
35
36 server.use((socket, next) => {
37 // @ts-ignore
38 if (socket.request._query.fail)
39 return next(new Error("Auth failed (main namespace)"));
40 next();
41 });
42
43 server.of("/no").use((socket, next) => {
44 next(new Error("Auth failed (custom namespace)"));
45 });
46
47 server.on("connection", (socket) => {
48 // simple test
49 socket.on("hi", () => {
50 socket.emit("hi");
51 });
52
53 socket.on("echo", (arg, cb) => {
54 cb(arg);
55 });
56
57 // ack tests
58 socket.on("ack", () => {
59 socket.emit("ack", (a, b) => {
60 if (a === 5 && b.test) {
61 socket.emit("got it");

Callers 15

runFunction · 0.90
beforeAllFunction · 0.90
createHttpServerFunction · 0.85
beforeAllFunction · 0.85
worker.jsFile · 0.85
listenFunction · 0.85
createHttpServerFunction · 0.85
server.jsFile · 0.85
index.tsFile · 0.85
initFunction · 0.85
redis.tsFile · 0.85
in-memory.tsFile · 0.85

Calls 7

ofMethod · 0.95
useMethod · 0.95
eqlMethod · 0.80
emitMethod · 0.65
callbackFunction · 0.50
cbFunction · 0.50
onMethod · 0.45

Tested by

no test coverage detected