phetsims / wave-on-a-string

"Wave on a String" is an educational simulation in HTML5, by PhET Interactive Simulations.
http://phet.colorado.edu/en/simulation/wave-on-a-string
GNU General Public License v3.0
7 stars 8 forks source link

branch: websocket #130

Open jessegreenberg opened 5 years ago

jessegreenberg commented 5 years ago

Like #117. But instead of using nexus we are using a basic websocket. Once a server is set up, the WebSocket can be used to control the position of the wrench by the orientation of a phone or mobile device.

jessegreenberg commented 5 years ago

This was pretty simple to set up, changes to sim code were almost identical to changes for nexus in #117 (which also is driven by WebSocket). The tricky part was setting up the server. This documentation is in the branch in WOASModel.

    // hacks for websocket!!
    // NOTE: You will have to change this IP to the devices adress, and the devices MUST be on the same network
    // Take a look at this example on how to set up a websocket with npm:
    // https://www.sitepoint.com/real-time-apps-websockets-server-sent-events/
    // 
    // Then in the client webpage, add a listener to the page that monitors device orientation like
    // var handleOrientation = function( event ) {
    //   var absolute = event.absolute;
    //   var alpha    = event.alpha;
    //   var beta     = event.beta;
    //   var gamma    = event.gamma;
    //   
    //   var json = JSON.stringify( {
    //     message: 'orientation event',
    //     beta: beta,
    //     absolute: event.absolute,
    //     alpha: event.alpha,
    //     gamma: event.gamma
    //   } );
    //   socket.send(json);
    // }