//-------------------------------------------------------------- void ofApp::onOpen( ofxLibwebsockets::Event& args ){ cout<<"new connection open"<<endl; cout<<args.conn.getClientIP()<< endl; Drawing * d = new Drawing(); d->_id = canvasID++; d->color.set(ofRandom(255),ofRandom(255),ofRandom(255));; d->conn = &( args.conn ); drawings.insert( make_pair( d->_id, d )); // send "setup" args.conn.send( d->getJSONString("setup") ); // send drawing so far map<int, Drawing*>::iterator it = drawings.begin(); for (it; it != drawings.end(); ++it){ Drawing * drawing = it->second; if ( d != drawing ){ for ( int i=0; i<drawing->points.size(); i++){ string x = ofToString(drawing->points[i].x); string y = ofToString(drawing->points[i].y); server.send( "{\"id\":"+ ofToString(drawing->_id) + ",\"point\":{\"x\":\""+ x+"\",\"y\":\""+y+"\"}," + drawing->getColorJSON() +"}"); } } } }
//-------------------------------------------------------------- void ofApp::onOpen( ofxLibwebsockets::Event& args ){ bConnected = true; cout<<"new connection open"<<endl; cout<<args.conn.getClientIP()<< endl; // send drawing so far map<int, Drawing*>::iterator it = drawings.begin(); for (it; it != drawings.end(); ++it){ Drawing * drawing = it->second; for ( int i=0; i<(int)drawing->points.size(); i++){ string x = ofToString(drawing->points[i].x); string y = ofToString(drawing->points[i].y); client.send( "{\"id\":"+ ofToString(drawing->_id) + ",\"point\":{\"x\":\""+ x+"\",\"y\":\""+y+"\"}," + drawing->getColorJSON() +"}"); } } }
//-------------------------------------------------------------- void ofApp::mousePressed(int x, int y, int button){ ofPoint p(x,y); map<int, Drawing*>::iterator it = drawings.find(0); Drawing * d = it->second; d->addPoint(p); server.send( "{\"id\":-1,\"point\":{\"x\":\""+ ofToString(x)+"\",\"y\":\""+ofToString(y)+"\"}," + d->getColorJSON() +"}"); }
//-------------------------------------------------------------- void ofApp::mousePressed(int x, int y, int button){ ofPoint p(x,y); map<int, Drawing*>::iterator it = drawings.find(id); if ( it == drawings.end() ) return; Drawing * d = it->second; d->addPoint(p); client.send( "{\"id\":"+ ofToString(id) + ",\"point\":{\"x\":\""+ ofToString(x)+"\",\"y\":\""+ofToString(y)+"\"}," + d->getColorJSON() +"}"); }