@@ -129,16 +129,23 @@ void Haply_Inverse3Controller::initDevice()
129129 reconn.min_delay = 1000 ;
130130 reconn.max_delay = 5000 ;
131131 reconn.delay_policy = 2 ;
132- m_ws.setReconnect (&reconn);
132+
133+ m_ws = std::make_unique<WebSocketClient>();
134+ m_ws->setReconnect (&reconn);
133135
134136 m_initDevice = true ;
135137}
136138
137139
138140void Haply_Inverse3Controller::disconnect ()
139141{
140- if (m_ws.isConnected ()) {
141- m_ws.close ();
142+ if (m_ws->isConnected ()) {
143+ m_ws->close ();
144+ }
145+
146+ if (m_ws != nullptr )
147+ {
148+ m_ws.release ();
142149 }
143150}
144151
@@ -150,15 +157,15 @@ bool Haply_Inverse3Controller::createHapticThreads()
150157 m_terminateCopy = false ;
151158 copy_thread = std::thread (&Haply_Inverse3Controller::CopyData, this , std::ref (this ->m_terminateCopy ), this );
152159
153- m_ws. onopen = [&]() {
160+ m_ws-> onopen = [&]() {
154161 std::cout << " [MyDeviceDriver] WebSocket opened." << std::endl;
155162 };
156163
157- m_ws. onmessage = [&](const std::string& msg) {
164+ m_ws-> onmessage = [&](const std::string& msg) {
158165 HapticsHandling (msg);
159166 };
160167
161- m_ws. onclose = [&]() {
168+ m_ws-> onclose = [&]() {
162169 std::cout << " [MyDeviceDriver] WebSocket closed." << std::endl;
163170 };
164171
@@ -167,7 +174,7 @@ bool Haply_Inverse3Controller::createHapticThreads()
167174
168175
169176void Haply_Inverse3Controller::connect () {
170- m_ws. open (" ws://localhost:10001" );
177+ m_ws-> open (" ws://localhost:10001" );
171178}
172179
173180
@@ -199,7 +206,7 @@ void Haply_Inverse3Controller::HapticsHandling(const std::string& msg)
199206
200207 std::cout << " [MyDeviceDriver] No devices found. Waiting for connection..." << std::endl;
201208 std::this_thread::sleep_for (1000ms);
202- m_ws. send (update_request.dump ());
209+ m_ws-> send (update_request.dump ());
203210
204211 return ;
205212 }
@@ -320,7 +327,7 @@ void Haply_Inverse3Controller::HapticsHandling(const std::string& msg)
320327 }
321328 }
322329
323- m_ws. send (request.dump ());
330+ m_ws-> send (request.dump ());
324331
325332 cptLoop++;
326333 ctime_t endTime = CTime::getRefTime ();
0 commit comments