/* */ #include "WebSocketSessionMan.h" #include "WebSocketSession.h" #include "RequestGroup.h" #include "json.h" #include "util.h" #include "WebSocketInteractionCommand.h" namespace aria2 { namespace rpc { WebSocketSessionMan::WebSocketSessionMan() {} WebSocketSessionMan::~WebSocketSessionMan() {} void WebSocketSessionMan::addSession (const SharedHandle& wsSession) { sessions_.insert(wsSession); } void WebSocketSessionMan::removeSession (const SharedHandle& wsSession) { sessions_.erase(wsSession); } void WebSocketSessionMan::addNotification (const std::string& method, const RequestGroup* group) { SharedHandle dict = Dict::g(); dict->put("jsonrpc", "2.0"); dict->put("method", method); SharedHandle eventSpec = Dict::g(); eventSpec->put("gid", util::itos(group->getGID())); SharedHandle params = List::g(); params->append(eventSpec); dict->put("params", params); std::string msg = json::encode(dict); for(WebSocketSessions::const_iterator i = sessions_.begin(), eoi = sessions_.end(); i != eoi; ++i) { (*i)->addTextMessage(msg); (*i)->getCommand()->updateWriteCheck(); } } } // namespace rpc } // namespace aria2