Skip to content

Commit

Permalink
fix: properly export the Socket class
Browse files Browse the repository at this point in the history
Before this change, `require("socket.io").Socket` would return
"undefined".

Note: having access to the Socket class allows users to modify its
prototype.

Related: socketio#3726
  • Loading branch information
darrachequesne committed May 6, 2021
1 parent 46b5809 commit 1e1fbb9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
3 changes: 2 additions & 1 deletion lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { Decoder, Encoder, Packet, PacketType } from "socket.io-parser";
import debugModule = require("debug");
import url = require("url");
import type { IncomingMessage } from "http";
import type { Namespace, Server } from "./index";
import type { Server } from "./index";
import type { Namespace } from "./namespace";
import type { EventsMap } from "./typed-events";
import type { Socket } from "./socket";
import type { SocketId } from "socket.io-adapter";
Expand Down
2 changes: 2 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -803,5 +803,7 @@ emitterMethods.forEach(function (fn) {

module.exports = (srv?, opts?) => new Server(srv, opts);
module.exports.Server = Server;
module.exports.Namespace = Namespace;
module.exports.Socket = Socket;

export { Socket, ServerOptions, Namespace, BroadcastOperator, RemoteSocket };
9 changes: 1 addition & 8 deletions test/socket.io.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

import { Server, Socket } from "..";
import { Server, Socket, Namespace } from "..";
import { createServer } from "http";
import fs = require("fs");
import { join } from "path";
Expand Down Expand Up @@ -373,9 +373,6 @@ describe("socket.io", () => {
});

describe("namespaces", () => {
const { Socket } = require("../dist/socket");
const { Namespace } = require("../dist/namespace");

it("should be accessible through .sockets", () => {
const sio = new Server();
expect(sio.sockets).to.be.a(Namespace);
Expand Down Expand Up @@ -2391,8 +2388,6 @@ describe("socket.io", () => {
});

describe("middleware", () => {
const { Socket } = require("../dist/socket");

it("should call functions", (done) => {
const srv = createServer();
const sio = new Server(srv);
Expand Down Expand Up @@ -2581,8 +2576,6 @@ describe("socket.io", () => {
});

describe("socket middleware", () => {
const { Socket } = require("../dist/socket");

it("should call functions", (done) => {
const srv = createServer();
const sio = new Server(srv);
Expand Down

0 comments on commit 1e1fbb9

Please sign in to comment.