Skip to main content
Version: 2.1.x

MessageHandlers

Message handlers are basic event handlers for websocket messages. They are called message handlers because you can use ZilaWS to listen to local events such as new connections with event handlers. The two are not the same thing.

Message or event handler?

Message handlers are for websocket messages/waiters. Event handlers are for local events like a new connection on the server side or disconnecting on the client side.

Usage

You can define MesageHandlers either on client or server side. In this example, we'll use them on the server.

server.ts
server.setMessageHandler("Login", (client, username: string, password: string) => {
const token: string | undefined = loginUser(username, password);
if(token) {
return `SUCCESS:token`;
}else {
return `FAIL:BadCredentials`;
}
});
client.ts
const resp = await client.waiter("Login", usernameInput, passwordInput);

Playground