encode websocket response