Skip to content

Commit

Permalink
Merge branch '0.9.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
robotconscience committed Mar 28, 2016
2 parents b425c97 + 648e1fe commit c9a9655
Show file tree
Hide file tree
Showing 9 changed files with 7 additions and 50 deletions.
3 changes: 1 addition & 2 deletions libs/ofxLibwebsockets/include/ofxLibwebsockets/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace ofxLibwebsockets {
}

// send any binary data
void sendBinary( ofBuffer buffer );
void sendBinary( ofBuffer & buffer );
void sendBinary( unsigned char * data, int size );
void sendBinary( char * data, int size );

Expand All @@ -76,7 +76,6 @@ namespace ofxLibwebsockets {
ofAddListener( clientProtocol.oncloseEvent, app, &T::onClose);
ofAddListener( clientProtocol.onidleEvent, app, &T::onIdle);
ofAddListener( clientProtocol.onmessageEvent, app, &T::onMessage);
ofAddListener( clientProtocol.onbroadcastEvent, app, &T::onBroadcast);
}

// get pointer to libwebsockets connection wrapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace ofxLibwebsockets {
sendBinary( (char *) image.getPixels().getData(), size );
}

void sendBinary( ofBuffer buffer );
void sendBinary( ofBuffer & buffer );
void sendBinary( unsigned char * data, unsigned int size );
void sendBinary( char * data, unsigned int size );

Expand Down
1 change: 0 additions & 1 deletion libs/ofxLibwebsockets/include/ofxLibwebsockets/Events.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,4 @@ namespace ofxLibwebsockets {
ofEvent<ofxLibwebsockets::Event> onClose;
ofEvent<ofxLibwebsockets::Event> onIdle;
ofEvent<ofxLibwebsockets::Event> onMessage;
ofEvent<ofxLibwebsockets::Event> onBroadcast;
};*/
5 changes: 0 additions & 5 deletions libs/ofxLibwebsockets/include/ofxLibwebsockets/Protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ namespace ofxLibwebsockets {
virtual bool allowClient(const std::string name,
const std::string ip) const;

void broadcast(const std::string& message);

unsigned int idx;
unsigned int rx_buffer_size;

Expand All @@ -49,7 +47,6 @@ namespace ofxLibwebsockets {
virtual void onerror (Event& args);
virtual void onidle (Event& args);
virtual void onmessage (Event& args);
virtual void onbroadcast(Event& args);

// internal events: called by Reactor
ofEvent<Event> onconnectEvent;
Expand All @@ -58,7 +55,6 @@ namespace ofxLibwebsockets {
ofEvent<Event> onerrorEvent;
ofEvent<Event> onidleEvent;
ofEvent<Event> onmessageEvent;
ofEvent<Event> onbroadcastEvent;

bool defaultAllowPolicy;
std::map<std::string, bool> allowRules;
Expand All @@ -74,7 +70,6 @@ namespace ofxLibwebsockets {
void _onerror (Event& args);
void _onidle (Event& args);
void _onmessage (Event& args);
void _onbroadcast (Event& args);

bool _allowClient(const std::string name,
const std::string ip) const;
Expand Down
10 changes: 2 additions & 8 deletions libs/ofxLibwebsockets/include/ofxLibwebsockets/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,7 @@ namespace ofxLibwebsockets {
// close the server
void close();

// broadcast a message to all connections
void broadcast( string message );

// send to all connections
// (sends normal message instead of broadcast)
// send to all connections
void send( string message );

// send anything that has pixels to all connections
Expand All @@ -81,7 +77,7 @@ namespace ofxLibwebsockets {
}

// send any binary data to all connections
void sendBinary( ofBuffer buffer );
void sendBinary( ofBuffer & buffer );
void sendBinary( unsigned char * data, int size );
void sendBinary( char * data, int size );

Expand All @@ -95,7 +91,6 @@ namespace ofxLibwebsockets {
ofAddListener( serverProtocol.oncloseEvent, app, &T::onClose);
ofAddListener( serverProtocol.onidleEvent, app, &T::onIdle);
ofAddListener( serverProtocol.onmessageEvent, app, &T::onMessage);
ofAddListener( serverProtocol.onbroadcastEvent, app, &T::onBroadcast);
}

template<class T>
Expand All @@ -105,7 +100,6 @@ namespace ofxLibwebsockets {
ofRemoveListener( serverProtocol.oncloseEvent, app, &T::onClose);
ofRemoveListener( serverProtocol.onidleEvent, app, &T::onIdle);
ofRemoveListener( serverProtocol.onmessageEvent, app, &T::onMessage);
ofRemoveListener( serverProtocol.onbroadcastEvent, app, &T::onBroadcast);
}

//getters
Expand Down
2 changes: 1 addition & 1 deletion libs/ofxLibwebsockets/src/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ namespace ofxLibwebsockets {
}

//--------------------------------------------------------------
void Client::sendBinary( ofBuffer buffer ){
void Client::sendBinary( ofBuffer & buffer ){
if ( connection != NULL){
connection->sendBinary(buffer);
}
Expand Down
2 changes: 1 addition & 1 deletion libs/ofxLibwebsockets/src/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ namespace ofxLibwebsockets {
}

//--------------------------------------------------------------
void Connection::sendBinary( ofBuffer buffer ){
void Connection::sendBinary( ofBuffer & buffer ){
sendBinary(buffer.getData(), buffer.size());
}

Expand Down
22 changes: 0 additions & 22 deletions libs/ofxLibwebsockets/src/Protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ namespace ofxLibwebsockets {
ofAddListener(oncloseEvent, this, &Protocol::_onclose);
ofAddListener(onidleEvent, this, &Protocol::_onidle);
ofAddListener(onmessageEvent, this, &Protocol::_onmessage);
ofAddListener(onbroadcastEvent, this, &Protocol::_onbroadcast);
ofAddListener(onerrorEvent, this, &Protocol::_onerror);
rx_buffer_size = OFX_LWS_MAX_BUFFER;
idle = false;
Expand All @@ -33,7 +32,6 @@ namespace ofxLibwebsockets {
ofRemoveListener(oncloseEvent, this, &Protocol::_onclose);
ofRemoveListener(onidleEvent, this, &Protocol::_onidle);
ofRemoveListener(onmessageEvent, this, &Protocol::_onmessage);
ofRemoveListener(onbroadcastEvent, this, &Protocol::_onbroadcast);
ofRemoveListener(onerrorEvent, this, &Protocol::_onerror);
rx_buffer_size = OFX_LWS_MAX_BUFFER;
idle = false;
Expand Down Expand Up @@ -94,24 +92,4 @@ namespace ofxLibwebsockets {
}

void Protocol::onmessage(Event&args){}

//--------------------------------------------------------------
void Protocol::_onbroadcast(Event& args){ onbroadcast(args); }

void Protocol::onbroadcast(Event&args){ args.conn.send(args.message); }

//--------------------------------------------------------------
void Protocol::broadcast(const std::string& message){
std::string buf(LWS_SEND_BUFFER_PRE_PADDING+message.size()+LWS_SEND_BUFFER_POST_PADDING, 0);
unsigned char *p = (unsigned char*)&buf[LWS_SEND_BUFFER_PRE_PADDING];

if (reactor != NULL)
{
memcpy(p, message.c_str(), message.size());
//int n = libwebsockets_broadcast(&reactor->lws_protocols[idx], p, message.size());
int n = libwebsocket_callback_on_writable_all_protocol(&reactor->lws_protocols[idx]);
if (n < 0)
fprintf(stderr, "ERROR writing to socket");
}
}
}
10 changes: 1 addition & 9 deletions libs/ofxLibwebsockets/src/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,6 @@ namespace ofxLibwebsockets {
}
libwebsocket_context_destroy(context);
}

//--------------------------------------------------------------
void Server::broadcast( string message ){
// loop through all protocols and broadcast!
for (int i=0; i<protocols.size(); i++){
protocols[i].second->broadcast( message );
}
}

//--------------------------------------------------------------
void Server::send( string message ){
Expand All @@ -168,7 +160,7 @@ namespace ofxLibwebsockets {
}

//--------------------------------------------------------------
void Server::sendBinary( ofBuffer buffer ){
void Server::sendBinary( ofBuffer & buffer ){
sendBinary(buffer.getData(), buffer.size());
}

Expand Down

0 comments on commit c9a9655

Please sign in to comment.