refactor server-client websocket event handling