36 : m_localEndpoint(localEndpoint)
37 , m_pingInterval(10000)
47 m_server.set_open_handler(bind(&WebSocketChannel::handleOpen,
this, _1));
48 m_server.set_close_handler(bind(&WebSocketChannel::handleClose,
this, _1));
49 m_server.set_message_handler(bind(&WebSocketChannel::handleMessage,
this, _1, _2));
52 m_server.set_pong_handler(bind(&WebSocketChannel::handlePong,
this, _1));
53 m_server.set_pong_timeout_handler(bind(&WebSocketChannel::handlePongTimeout,
this, _1));
56 m_server.set_reuse_addr(
true);
60 WebSocketChannel::setPingInterval(time::milliseconds interval)
62 BOOST_ASSERT(!m_server.is_listening());
64 m_pingInterval = interval;
68 WebSocketChannel::setPongTimeout(time::milliseconds timeout)
70 BOOST_ASSERT(!m_server.is_listening());
72 m_server.set_pong_timeout(static_cast<long>(timeout.count()));
76 WebSocketChannel::handlePongTimeout(websocketpp::connection_hdl hdl)
78 auto it = m_channelFaces.find(hdl);
79 if (it != m_channelFaces.end()) {
88 WebSocketChannel::handlePong(websocketpp::connection_hdl hdl)
90 auto it = m_channelFaces.find(hdl);
91 if (it != m_channelFaces.end()) {
100 WebSocketChannel::handleMessage(websocketpp::connection_hdl hdl,
101 websocket::Server::message_ptr msg)
103 auto it = m_channelFaces.find(hdl);
104 if (it != m_channelFaces.end()) {
113 WebSocketChannel::handleOpen(websocketpp::connection_hdl hdl)
115 auto linkService = make_unique<face::GenericLinkService>();
116 auto transport = make_unique<face::WebSocketTransport>(hdl, ref(m_server), m_pingInterval);
117 auto face = make_shared<Face>(std::move(linkService), std::move(transport));
119 m_channelFaces[hdl] = face;
122 m_onFaceCreatedCallback(face);
126 WebSocketChannel::handleClose(websocketpp::connection_hdl hdl)
128 auto it = m_channelFaces.find(hdl);
129 if (it != m_channelFaces.end()) {
140 if (m_server.is_listening()) {
141 NFD_LOG_WARN(
"[" << m_localEndpoint <<
"] Already listening");
145 m_onFaceCreatedCallback = onFaceCreated;
146 m_server.listen(m_localEndpoint);
147 m_server.start_accept();
153 return m_channelFaces.size();
size_t size() const
Get number of faces in the channel.
represents the underlying protocol and address used by a Face
void connectFaceClosedSignal(Face &face, const std::function< void()> &f)
invokes a callback when the face is closed
detail::SimulatorIo & getGlobalIoService()
WebSocketChannel(const websocket::Endpoint &localEndpoint)
Create WebSocket channel for the local endpoint.
Copyright (c) 2011-2015 Regents of the University of California.
void listen(const FaceCreatedCallback &onFaceCreated)
Enable listening on the local endpoint, accept connections, and create faces when remote host makes a...
void setUri(const FaceUri &uri)
#define NFD_LOG_WARN(expression)
A Transport that communicates on a WebSocket connection.
function< void(const shared_ptr< Face > &newFace)> FaceCreatedCallback
Prototype for the callback that is invoked when the face is created (as a response to incoming connec...
boost::asio::ip::tcp::endpoint Endpoint
#define NFD_LOG_INIT(name)