11#include " ofApp.h"
22
3+ // quality of image: higher is more readable, lower is faster!
4+ int jpegquality = 100 ;
5+
36// --------------------------------------------------------------
47void ofApp::setup (){
5- // setup a server with default options on port 9092
6- // - pass in true after port to set up with SSL
7- // bool connected = server.setup( 9092 );
8-
9- // Uncomment this to set up a server with a protocol
10- // Right now, clients created via libwebsockets that are connecting to servers
11- // made via libwebsockets seem to want a protocol. Hopefully this gets fixed,
12- // but until now you have to do something like this:
13-
148 // setup video grabber
159 video.listDevices ();
1610 bVideoSetup = video.initGrabber (640 ,480 );
1711
12+ // setup a server with default options on port 9093
1813 ofxLibwebsockets::ServerOptions options = ofxLibwebsockets::defaultServerOptions ();
1914 options.port = 9093 ;
2015 bool connected = server.setup ( options );
@@ -42,7 +37,7 @@ void ofApp::update(){
4237 // the second param == quality. play with this to get a better framerate
4338 // you can also try resizing your image!
4439 // currentImage.resize(160, 120);
45- unsigned char * compressed = turbo.compress (currentImage,50 ,&size);
40+ unsigned char * compressed = turbo.compress (currentImage,jpegquality ,&size);
4641 server.sendBinary (compressed, size);
4742 free (compressed);
4843 }
@@ -59,6 +54,12 @@ void ofApp::draw(){
5954 }
6055 if ( bVideoSetup ) video.draw (0 ,0 );
6156 ofDrawBitmapString (ofToString (ofGetFrameRate ())+" fps" , 10 , 15 );
57+
58+ ofSetColor (255 );
59+ ofDrawBitmapString (" WebSocket server setup at " +ofToString ( server.getPort () ) + ( server.usingSSL () ? " with SSL" : " without SSL" ), 10 , 40 );
60+
61+ ofDrawBitmapString (" Click anywhere to open up browser client" , 10 , 60 );
62+ ofDrawBitmapString (" +/- changes image quality: " +ofToString (jpegquality), 10 , 80 );
6263}
6364
6465// --------------------------------------------------------------
@@ -107,7 +108,13 @@ void ofApp::onBroadcast( ofxLibwebsockets::Event& args ){
107108
108109// --------------------------------------------------------------
109110void ofApp::keyPressed (int key){
110-
111+ if ( key == ' +' ){
112+ jpegquality ++;
113+ jpegquality = jpegquality > 100 ? 100 : jpegquality;
114+ } else if (key == ' -' ){
115+ jpegquality--;
116+ jpegquality = jpegquality < 0 ? 0 : jpegquality;
117+ }
111118}
112119
113120// --------------------------------------------------------------
@@ -127,7 +134,12 @@ void ofApp::mouseDragged(int x, int y, int button){
127134
128135// --------------------------------------------------------------
129136void ofApp::mousePressed (int x, int y, int button){
130-
137+ string url = " http" ;
138+ if ( server.usingSSL () ){
139+ url += " s" ;
140+ }
141+ url += " ://localhost:" + ofToString ( server.getPort () );
142+ ofLaunchBrowser (url);
131143}
132144
133145// --------------------------------------------------------------
0 commit comments