@@ -24,6 +24,7 @@ namespace ofxLibwebsockets {
2424 buf = (unsigned char *)calloc (LWS_SEND_BUFFER_PRE_PADDING+bufferSize+LWS_SEND_BUFFER_POST_PADDING, sizeof (unsigned char ));
2525 binaryBuf = (unsigned char *)calloc (LWS_SEND_BUFFER_PRE_PADDING+bufferSize+LWS_SEND_BUFFER_POST_PADDING, sizeof (unsigned char ));
2626 }
27+ idle = false ;
2728 }
2829
2930 // --------------------------------------------------------------
@@ -109,7 +110,7 @@ namespace ofxLibwebsockets {
109110 // --------------------------------------------------------------
110111 void Connection::update (){
111112 // process standard ws messages
112- if ( messages_text.size () > 0 && protocol-> idle ){
113+ if ( messages_text.size () > 0 && idle ){
113114 // grab first packet
114115 TextPacket & packet = messages_text[0 ];
115116
@@ -131,7 +132,7 @@ namespace ofxLibwebsockets {
131132
132133 // actual write to libwebsockets
133134 memcpy (&buf[LWS_SEND_BUFFER_PRE_PADDING], packet.message .c_str () + packet.index , dataSize );
134- protocol-> idle = false ;
135+ idle = false ;
135136
136137 int n = libwebsocket_write (ws, &buf[LWS_SEND_BUFFER_PRE_PADDING], dataSize, (libwebsocket_write_protocol) writeMode );
137138
@@ -152,7 +153,7 @@ namespace ofxLibwebsockets {
152153 }
153154
154155 // process binary messages
155- if ( messages_binary.size () > 0 && protocol-> idle ){
156+ if ( messages_binary.size () > 0 && idle ){
156157 if ( messages_binary.size () > 0 ){
157158 BinaryPacket & packet = messages_binary[0 ];
158159
@@ -170,7 +171,7 @@ namespace ofxLibwebsockets {
170171 memcpy (&binaryBuf[LWS_SEND_BUFFER_PRE_PADDING], packet.data + packet.index , dataSize );
171172
172173 // this sets the protocol to wait until "idle"
173- protocol-> idle = false ; // todo: this should be automatic on write!
174+ idle = false ; // todo: this should be automatic on write!
174175
175176 int n = libwebsocket_write (ws, &binaryBuf[LWS_SEND_BUFFER_PRE_PADDING], dataSize, (libwebsocket_write_protocol) writeMode );
176177 libwebsocket_callback_on_writable (context, ws);
@@ -189,6 +190,18 @@ namespace ofxLibwebsockets {
189190 libwebsocket_callback_on_writable (context, ws);
190191 }
191192 }
193+ // --------------------------------------------------------------
194+ void Connection::setIdle ( bool isIdle ){
195+ idle = isIdle;
196+ static string dum =" " ;
197+ Event args (*this , dum);
198+ ofNotifyEvent (protocol->onidleEvent , args);
199+ }
200+
201+ // --------------------------------------------------------------
202+ bool Connection::isIdle (){
203+ return idle;
204+ }
192205
193206 // --------------------------------------------------------------
194207 bool Connection::operator ==( const Connection &other ){
0 commit comments