V
V
Vladislav1652020-11-20 15:01:33
Socket.io
Vladislav165, 2020-11-20 15:01:33

What does this error mean and how can I fix it?

import socketIO
This expression is not callable.
The type "typeof import("c:/Users/1/Desktop/NodeJS-WebRTC/node_modules/socket.io/dist/index")" does not contain a call signature.
The program code is attached:
import express, { Application } from "express";
import socketIO, { Server as SocketIOServer } from "socket.io";
import { createServer, Server as HTTPServer } from "http";
import path from "path";

export class Server {
private httpServer: HTTPServer;
private app: Application;
private io: SocketIOServer;

private activeSockets: string[] = [];

private readonly DEFAULT_PORT = 5000;

}

private initialize(): void {
this.app = express();
this.httpServer = createServer(this.app);
this.io = socketIO(this.httpServer);

this.configureApp();
this.configureRoutes();
this handleSocketConnection();
}

private configureApp(): void {
this.app.use(express.static(path.join(__dirname, "../public")));
}

private configureRoutes(): void {
this.app.get("/", (req, res) => {
res.sendFile("index.html");
});
}

private handleSocketConnection(): void {
this.io.on("connection", socket => {
const existingSocket = this.activeSockets.find(
existingSocket => existingSocket === socket.id
);

if (!existingSocket) {
this.activeSockets.push(socket.id);

socket.emit("update-user-list", {
users: this.activeSockets.filter(
existingSocket => existingSocket !== socket.id
)
});

socket.broadcast.emit("update-user-list", {
users: [socket.id]
});
}

socket.on("call-user", (data: any) => {
socket.to(data.to).emit("call-made", {
offer: data.offer,
socket: socket.
});
});

socket.on("make-answer", data => {
socket.to(data.to).emit("answer-made", {
socket: socket.id,
answer: data.answer
});
});

socket.on("reject-call", data => {
socket.to(data.from).emit("call-rejected", {
socket: socket.id
});
});

socket.on("disconnect", () => {
this.activeSockets = this.activeSockets.filter(
existingSocket => existingSocket !== socket.id
);
socket.broadcast.emit("remove-user", {
socketId: socket.
});
});
}

public listen(callback: (port: number) => void): void {
this.httpServer.listen(this.DEFAULT_PORT, () => {
callback(this.DEFAULT_PORT);
});
}
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question