Add stylus middleware. Add join, leave and message events to the chat protocol. Add event handlers for these events in the client and server.