import { Server } from "https://deno.land/x/socket_io@0.2.0/packages/socket.io/mod.ts";
Represents a Socket.IO server.
Examples
import { serve } from "https://deno.land/std@a.b.c/http/server.ts";
import { Server } from "https://deno.land/x/socket_io@x.y.z/mod.ts";
import { serve } from "https://deno.land/std@a.b.c/http/server.ts"; import { Server } from "https://deno.land/x/socket_io@x.y.z/mod.ts";
const io = new Server();
io.on("connection", (socket) => {
console.log(socket ${socket.id} connected
);
// send an event to the client socket.emit("foo", "bar");
socket.on("foobar", () => { // an event was received from the client });
// upon disconnection
socket.on("disconnect", (reason) => {
console.log(socket ${socket.id} disconnected due to ${reason}
);
});
});
await serve(io.handler(), { port: 3000, });
Constructors
Type Parameters
Properties
Sets a modifier for a subsequent event emission that the event data will only be broadcast to the current node.
Sets a modifier for a subsequent event emission that the event data may be lost if the client is not ready to receive messages (because of network slowness or other issues, or because they’re connected through long polling and is in the middle of a request-response cycle).
Methods
Executes the middleware for an incoming namespace not already created on the server.
Closes the server.
Makes the matching socket instances disconnect.
Note: this method also works within a cluster of multiple Socket.IO servers, with a compatible Adapter.
Emits to all connected clients.
Excludes a room when emitting.
Returns the matching socket instances.
Note: this method also works within a cluster of multiple Socket.IO servers, with a compatible Adapter.
Returns a request handler.
Targets a room when emitting. Similar to to()
, but might feel clearer in some cases:
Looks up a namespace.
Sends a message
event to all clients.
This method mimics the WebSocket.send() method.
Sends a message to the other Socket.IO servers of the cluster.
Makes the matching socket instances join the specified rooms.
Note: this method also works within a cluster of multiple Socket.IO servers, with a compatible Adapter.
Makes the matching socket instances leave the specified rooms.
Note: this method also works within a cluster of multiple Socket.IO servers, with a compatible Adapter.
Adds a timeout in milliseconds for the next operation.
Targets a room when emitting.
Registers a middleware, which is a function that gets executed for every incoming Socket.