new Server(optsopt)
The server class.
Parameters:
Name | Type | Attributes | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opts |
Object |
<optional> |
The Server and net.Server options.
Properties
|
Fires:
Members
rooms :Object
The rooms with at least one socket or more. The key is the room name and
the value an array of sockets.
Type:
- Object
sockets :Object
The connected sockets. The key is the Socket.id and the value a Socket instance.
Type:
- Object
Methods
close()
Disconnect all the clients and close the server.
emit(event, data, optsopt)
Emit an event, if no sockets or rooms are provided, the event
will be broadcasted to all connected sockets.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
event |
String | The event name. | |||||||||||||||||||||
data |
String | Number | Object | Buffer | Boolean | The data to send. | |||||||||||||||||||||
opts |
Object |
<optional> |
The options.
Properties
|
join(room, socketId)
Join to a room.
Parameters:
Name | Type | Description |
---|---|---|
room |
String | The room name. |
socketId |
String | The socket id. |
leave(room, socketId)
Leave a room.
Parameters:
Name | Type | Description |
---|---|---|
room |
String | The room name. |
socketId |
String | The socket id. |
leaveAll(socketId)
Leave all rooms.
Parameters:
Name | Type | Description |
---|---|---|
socketId |
String | The socket id. |
listen(portopt)
Start the server. It calls the underline net.Server#listen with the given arguments so
multiple optional arguments can be used.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
port |
Number |
<optional> |
The port to listen to, this is the most basic usage, check the link for more advanced usages. |
- Source:
- See:
stream(event, data, optsopt)
Creates and returns a stream.Writable instance that can be used to stream
binary data. If no opts.sockets or opts.rooms are provided, the stream
will be broadcasted to all connected sockets.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
event |
String | The event name. | |||||||||||||||||||||
data |
String | Number | Object | Buffer | Boolean | The data to send. | |||||||||||||||||||||
opts |
Object |
<optional> |
The options.
Properties
|
Events
close
Close event from net.Server.
connection
A new Socket was connected.
error
Error event from net.Server.
listening
Listening event from net.Server.