/* * IXWebSocketMessageQueue.h * Author: Korchynskyi Dmytro * Copyright (c) 2017-2019 Machine Zone, Inc. All rights reserved. */ #pragma once #include "IXWebSocket.h" #include #include #include namespace ix { // // A helper class to dispatch websocket message callbacks in your thread. // class WebSocketMessageQueue { public: WebSocketMessageQueue(WebSocket* websocket = nullptr); ~WebSocketMessageQueue(); void bindWebsocket(WebSocket* websocket); void setOnMessageCallback(const OnMessageCallback& callback); void poll(int count = 512); protected: struct Message { WebSocketMessageType type; std::string str; size_t wireSize; WebSocketErrorInfo errorInfo; WebSocketOpenInfo openInfo; WebSocketCloseInfo closeInfo; }; using MessageDataPtr = std::shared_ptr; MessageDataPtr popMessage(); private: WebSocket* _websocket = nullptr; OnMessageCallback _onMessageUserCallback; std::mutex _messagesMutex; std::list _messages; }; }