Skip to content

Commit d65b6ee

Browse files
fix: properly export the Socket class
Before this change, `require("socket.io").Socket` would return "undefined". Note: having access to the Socket class allows users to modify its prototype. Related: #3726
1 parent 3665aad commit d65b6ee

File tree

3 files changed

+5
-9
lines changed

3 files changed

+5
-9
lines changed

lib/client.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { Decoder, Encoder, Packet, PacketType } from "socket.io-parser";
22
import debugModule = require("debug");
33
import url = require("url");
44
import type { IncomingMessage } from "http";
5-
import type { Namespace, Server } from "./index";
5+
import type { Server } from "./index";
6+
import type { Namespace } from "./namespace";
67
import type { EventsMap } from "./typed-events";
78
import type { Socket } from "./socket";
89
import type { SocketId } from "socket.io-adapter";

lib/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,5 +803,7 @@ emitterMethods.forEach(function (fn) {
803803

804804
module.exports = (srv?, opts?) => new Server(srv, opts);
805805
module.exports.Server = Server;
806+
module.exports.Namespace = Namespace;
807+
module.exports.Socket = Socket;
806808

807809
export { Socket, ServerOptions, Namespace, BroadcastOperator, RemoteSocket };

test/socket.io.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22

3-
import { Server, Socket } from "..";
3+
import { Server, Socket, Namespace } from "..";
44
import { createServer } from "http";
55
import fs = require("fs");
66
import { join } from "path";
@@ -373,9 +373,6 @@ describe("socket.io", () => {
373373
});
374374

375375
describe("namespaces", () => {
376-
const { Socket } = require("../dist/socket");
377-
const { Namespace } = require("../dist/namespace");
378-
379376
it("should be accessible through .sockets", () => {
380377
const sio = new Server();
381378
expect(sio.sockets).to.be.a(Namespace);
@@ -2391,8 +2388,6 @@ describe("socket.io", () => {
23912388
});
23922389

23932390
describe("middleware", () => {
2394-
const { Socket } = require("../dist/socket");
2395-
23962391
it("should call functions", (done) => {
23972392
const srv = createServer();
23982393
const sio = new Server(srv);
@@ -2581,8 +2576,6 @@ describe("socket.io", () => {
25812576
});
25822577

25832578
describe("socket middleware", () => {
2584-
const { Socket } = require("../dist/socket");
2585-
25862579
it("should call functions", (done) => {
25872580
const srv = createServer();
25882581
const sio = new Server(srv);

0 commit comments

Comments
 (0)