mirror of
https://github.com/socketio/socket.io.git
synced 2026-01-13 17:07:54 -05:00
Usage:
```js
socket.timeout(5000).emit("my-event", (err) => {
if (err) {
// the client did not acknowledge the event in the given delay
}
});
```
47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
import type { Server } from "../..";
|
|
import {
|
|
io as ioc,
|
|
ManagerOptions,
|
|
Socket as ClientSocket,
|
|
SocketOptions,
|
|
} from "socket.io-client";
|
|
|
|
const expect = require("expect.js");
|
|
const i = expect.stringify;
|
|
|
|
// add support for Set/Map
|
|
const contain = expect.Assertion.prototype.contain;
|
|
expect.Assertion.prototype.contain = function (...args) {
|
|
if (typeof this.obj === "object") {
|
|
args.forEach((obj) => {
|
|
this.assert(
|
|
this.obj.has(obj),
|
|
function () {
|
|
return "expected " + i(this.obj) + " to contain " + i(obj);
|
|
},
|
|
function () {
|
|
return "expected " + i(this.obj) + " to not contain " + i(obj);
|
|
}
|
|
);
|
|
});
|
|
return this;
|
|
}
|
|
return contain.apply(this, args);
|
|
};
|
|
|
|
export function createClient(
|
|
io: Server,
|
|
nsp: string,
|
|
opts?: ManagerOptions & SocketOptions
|
|
): ClientSocket {
|
|
// @ts-ignore
|
|
const port = io.httpServer.address().port;
|
|
return ioc(`http://localhost:${port}${nsp}`, opts);
|
|
}
|
|
|
|
export function success(done: Function, io: Server, client: ClientSocket) {
|
|
io.close();
|
|
client.disconnect();
|
|
done();
|
|
}
|