(httpServer: HttpServer, io: Server)
| 5 | import { Adapter } from "socket.io-adapter"; |
| 6 | |
| 7 | async function init(httpServer: HttpServer, io: Server) { |
| 8 | // Engine.IO handshake |
| 9 | const sid = await eioHandshake(httpServer); |
| 10 | |
| 11 | // Socket.IO handshake |
| 12 | await eioPush(httpServer, sid, "40"); |
| 13 | const handshakeBody = await eioPoll(httpServer, sid); |
| 14 | |
| 15 | expect(handshakeBody.startsWith("40")).to.be(true); |
| 16 | |
| 17 | const handshake = JSON.parse(handshakeBody.substring(2)); |
| 18 | |
| 19 | expect(handshake.sid).to.not.be(undefined); |
| 20 | // in that case, the handshake also contains a private session ID |
| 21 | expect(handshake.pid).to.not.be(undefined); |
| 22 | |
| 23 | io.emit("hello"); |
| 24 | |
| 25 | const message = await eioPoll(httpServer, sid); |
| 26 | |
| 27 | expect(message.startsWith('42["hello"')).to.be(true); |
| 28 | |
| 29 | const offset = JSON.parse(message.substring(2))[1]; |
| 30 | // in that case, each packet also includes an offset in the data array |
| 31 | expect(offset).to.not.be(undefined); |
| 32 | |
| 33 | await eioPush(httpServer, sid, "1"); |
| 34 | |
| 35 | return [handshake.sid, handshake.pid, offset]; |
| 36 | } |
| 37 | |
| 38 | describe("connection state recovery", () => { |
| 39 | it("should restore session and missed packets", async () => { |
no test coverage detected