Skip to content

Enables users to send events to iMotions from a web browser.

License

Notifications You must be signed in to change notification settings

ltcmdrkeen/imotions-web-bridge

Repository files navigation

iMotions-Web-Bridge

iMotions currently has no possibility to directly connect to it's event API from a web browser, as web browser cannot connect to UDP/TCP sockets but only to websockets.


  • Steps to send events:
    • Install Node.js from https://nodejs.org/en/download/ and run npm install
    • Adapt the index.js variables HOST and PORT to your iMotions setup (defaults should be fine)
    • Start the bridge server with node index.js
    • That's it! Connect from a web client and send events.

Example web client code

  // Creating websocket object depending on mozilla usage
  window.WebSocket = window.WebSocket || 	 window.MozWebSocket;

  // Connect to node websocket server
  var connection = new WebSocket('ws://127.0.0.1:1337');
  connection.onopen = function () {
    console.log("connection to iMotion node bridge ready");
    // Do the same as in the iMotions tutorial
    for(var i=0;i<100;i++){
      setTimeout(function(ws,i){
				// Send a test event:
        iMotionsEvent="E;1;EventSourceId;1;0.0;;;SampleId;" + i + ";" + i/10 + "\r\n"
        ws.send(iMotionsEvent);
				// Send a test marker:
				if(i % 2 == 0){
					iMotionsMarker = "M;1;;;CheckOut;Respondent completed the check out task\r\n";
				}else{
					iMotionsMarker = "M;1;;;CheckIn;Respondent started check in task\r\n";
				}

      },i*500,connection,i);
    }

  };
  connection.onerror = function (error) {
    console.log("Error while connecting to iMotions node bridge")
  };

About

Enables users to send events to iMotions from a web browser.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published