install- install npm packages,start- interactive watch mode to automatically transpile sourcebuild- transpile TypeScript to ES6start:prod- run in production modestart:dev- run in development modestart:debug- run in debug modelint- lint ts fileslint:fix- lint and format filestest- run jest test runnertest:watch- run jest tests in watch modetest:cov- run jest tests and show coverage
First the client has to connect with a handshake query. Otherwise the client will be disconnected by the server. Currently there is no response after a successful handshake. A client must be in a room. The room must exist and created by the server.
const socket = io('http://localhost:9001', {
query: {
roomId: 1,
name: 'alice',
},
});A client can send a message, which must be typeof a ClientMessage. It contains just a payload, which represents plain text. The event type of the message must be message.
export interface ClientMessage {
payload: string;
}
const clientMessage: ClientMessage = { payload: 'text' };
clientSocket.emit('message', clientMessage);The Server combines the ClientMessage with the username from the sender. This type of Message is called ServerMessage. This message will be send to all clients in that room including the sender.
export interface ServerMessage {
payload: string;
username: string;
}
clientSocket.on('message', (serverMessage: ServerMessage) => {});