From 920227017dd1a6e4df7582b9b45c2604fdaed5d1 Mon Sep 17 00:00:00 2001 From: Soravis Prakkamakul Date: Wed, 16 Dec 2015 00:54:05 +0700 Subject: [PATCH] Remove browser window size from initialization API --- dist/eyex-chrome.js | 2 +- examples/chromeapp/scripts/eyex-chrome.js | 2 +- src/tobii-eyex-client.js | 13 ++++++------- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/dist/eyex-chrome.js b/dist/eyex-chrome.js index ed24bf5..451f145 100644 --- a/dist/eyex-chrome.js +++ b/dist/eyex-chrome.js @@ -1 +1 @@ -!function(e){function t(e,t){this.host=e,this.port=t,this._onReceive=this._onReceive.bind(this),this._onReceiveError=this._onReceiveError.bind(this),this.callbacks={connect:null,disconnect:null,recv:null,sent:null},this.socketId=null,this.isConnected=!1,s("initialized tcp client")}function s(e){console.log(e)}function o(e){console.error(e)}t.prototype.connect=function(e){this.callbacks.connect=e,chrome.sockets.tcp.create({},this._onCreate.bind(this))},t.prototype.sendMessage=function(e,t){this.callbacks.sent=t,this._stringToArrayBuffer(e+"\n",function(e){chrome.sockets.tcp.send(this.socketId,e,this._onSendComplete.bind(this))}.bind(this))},t.prototype.sendAPIMessage=function(e,t,s,o){var i={category:e,request:t,values:s};this.sendMessage(JSON.stringify(i),o)},t.prototype.sendHeartbeat=function(e){var t={category:"heartbeat"};this.sendMessage(JSON.stringify(t),e)},t.prototype.startTracker=function(){this.sendAPIMessage(CATEGORY.TRACKER,REQUEST.SET,{push:!0,version:1})},t.prototype.addResponseListener=function(e){this.callbacks.recv=e},t.prototype.disconnect=function(){chrome.sockets.tcp.onReceive.removeListener(this._onReceive),chrome.sockets.tcp.onReceiveError.removeListener(this._onReceiveError),chrome.sockets.tcp.disconnect(this.socketId),chrome.sockets.tcp.close(this.socketId),this.socketId=null,this.isConnected=!1},t.prototype._onCreate=function(e){chrome.runtime.lastError&&o("Unable to create socket: "+chrome.runtime.lastError.message),this.socketId=e.socketId,this.isConnected=!0,chrome.sockets.tcp.connect(this.socketId,this.host,this.port,this._onConnectComplete.bind(this))},t.prototype._onConnectComplete=function(e){return 0>e?void o("Unable to connect to server"):(chrome.sockets.tcp.onReceive.addListener(this._onReceive),chrome.sockets.tcp.onReceiveError.addListener(this._onReceiveError),void(this.callbacks.connect&&this.callbacks.connect()))},t.prototype._onReceive=function(e){e.socketId==this.socketId&&this.callbacks.recv&&this._arrayBufferToString(e.data,function(e){this.callbacks.recv(e)}.bind(this))},t.prototype._onReceiveError=function(e){e.socketId==this.socketId&&o("Unable to receive data from socket: "+e.resultCode)},t.prototype._onSendComplete=function(e){this.callbacks.sent&&this.callbacks.sent(e)},t.prototype._arrayBufferToString=function(e,t){var s=new FileReader;s.onload=function(e){t(e.target.result)};var o=new Blob([e],{type:"application/octet-stream"});s.readAsText(o)},t.prototype._stringToArrayBuffer=function(e,t){var s=new Blob([e]),o=new FileReader;o.onload=function(e){t(e.target.result)},o.readAsArrayBuffer(s)},e.TcpClient=t}(window),function(e){function t(t){this.latestRequestId=1,this.options=c,this.trackerInfo=r,this.callback={},this.apiCallback={},this.frame={smoothXY:{x:0,y:0},deltaTime:0,lastFrameTime:new Date,smoothStatus:{gazing:{value:!1,counter:0},eyes:{value:!1,counter:0},presence:{value:!1,counter:0},fail:{value:!1,counter:0},lost:{value:!1,counter:0}},status:{presence:!1},lefteye:{pcenter:{x:0,y:0}},righteye:{pcenter:{x:0,y:0}},blinkCounter:0,blinkPhase:n.NOT_STARTED},this._onAPIMessageReceived=this._onAPIMessageReceived.bind(this),this.callback.onFrameCallback=t.onFrameCallback,this.callback.onBlinkCallback=t.onBlinkCallback,this.options.browserScreenWidth=t.browserScreenWidth,this.options.browserScreenHeight=t.browserScreenHeight,s=new e.TcpClient(this.options.host,this.options.port),s.addResponseListener(this._onAPIMessageReceived),s.connect(function(e){console.log("EyeTribe Connected"),this.getTrackerInfo(function(e){console.log(e),void 0!=e&&void 0!=e.screen_bounds&&(this.options.nativeScreenX=e.screen_bounds.x,this.options.nativeScreenY=e.screen_bounds.y,this.options.nativeScreenWidth=e.screen_bounds.width,this.options.nativeScreenHeight=e.screen_bounds.height)}.bind(this))}.bind(this))}var s,o={REQUEST:"request",RESPONSE:"response",EVENT:"event"},i={TRACKER:"tracker",CALIBRATION:"calibration"},n={NOT_STARTED:0,BEFORE_EYES_CLOSED:1,EYES_CLOSED:2,AFTER_EYES_CLOSED:3},r={push:!1,version:1,trackerstate:void 0,framerate:30,iscalibrated:!1,iscalibrating:!1,calibresult:void 0,frame:void 0,screenindex:0,screenresw:1024,screenresh:768,screenpsyw:1,screenpsyh:1},c={host:"127.0.0.1",port:6555,smoothingFactor:.9,smoothStatusDelay:100,blinkEyesClosePeriod:1e3,blinkEyesOpenPeriod:50,blinkEyesCloseErrorTolerance:500,nativeScreenWidth:1920,nativeScreenHeight:1280,nativeScreenX:0,nativeScreenY:0,browserScreenWidth:1280,browserScreenHeight:852};t.prototype._onAPIMessageReceived=function(e){try{if(e=JSON.parse(e),"response"===e.type){if(void 0!=e.requestId){var t=this.apiCallback[e.requestId];"function"==typeof t&&t(e.data)}}else"request"===e.type||"event"===e.type&&"frame"===e.event_type&&(this._processFrame(e.data),this.callback.onFrameCallback(this.frame))}catch(s){console.log(s)}},t.prototype._sendAPIMessage=function(e,t,o,i,n){var r={type:e,resource:t,path:o};if("request"==e){var c=this.latestRequestId++;r.requestId=c,this.apiCallback[c]=n}void 0!=i&&(r.parameters=i),s.sendMessage(JSON.stringify(r))},t.prototype.getTrackerInfo=function(e){this._sendAPIMessage(o.REQUEST,i.TRACKER,"get.basic_info",void 0,e)},t.prototype.requestCalibration=function(e){this._sendAPIMessage(o.REQUEST,i.CALIBRATION,"start",void 0,e)},t.prototype._processFrame=function(e){this.frame.status.presence=e.userPresence,this.frame.deltaTime=new Date-this.frame.lastFrameTime,this.frame.lastFrameTime=new Date,this.frame.lefteye.pcenter.x=1-e.eyePosition.leftNormalized.x,this.frame.lefteye.pcenter.y=e.eyePosition.leftNormalized.y,this.frame.righteye.pcenter.x=1-e.eyePosition.rightNormalized.x,this.frame.righteye.pcenter.y=e.eyePosition.rightNormalized.y,e.gaze.x=(e.gaze.x-this.options.nativeScreenX)*this.options.browserScreenWidth/this.options.nativeScreenWidth,e.gaze.y=(e.gaze.y-this.options.nativeScreenY)*this.options.browserScreenHeight/this.options.nativeScreenHeight;var t=Math.abs(this.frame.smoothXY.x-e.gaze.x),s=Math.abs(this.frame.smoothXY.y-e.gaze.y);Math.sqrt(t*t+s*s);this.frame.smoothXY.x=this.frame.smoothXY.x*this.options.smoothingFactor+e.gaze.x*(1-this.options.smoothingFactor),this.frame.smoothXY.y=this.frame.smoothXY.y*this.options.smoothingFactor+e.gaze.y*(1-this.options.smoothingFactor)},e.TobiiEyeX=t}(window); \ No newline at end of file +!function(e){function t(e,t){this.host=e,this.port=t,this._onReceive=this._onReceive.bind(this),this._onReceiveError=this._onReceiveError.bind(this),this.callbacks={connect:null,disconnect:null,recv:null,sent:null},this.socketId=null,this.isConnected=!1,s("initialized tcp client")}function s(e){console.log(e)}function o(e){console.error(e)}t.prototype.connect=function(e){this.callbacks.connect=e,chrome.sockets.tcp.create({},this._onCreate.bind(this))},t.prototype.sendMessage=function(e,t){this.callbacks.sent=t,this._stringToArrayBuffer(e+"\n",function(e){chrome.sockets.tcp.send(this.socketId,e,this._onSendComplete.bind(this))}.bind(this))},t.prototype.sendAPIMessage=function(e,t,s,o){var i={category:e,request:t,values:s};this.sendMessage(JSON.stringify(i),o)},t.prototype.sendHeartbeat=function(e){var t={category:"heartbeat"};this.sendMessage(JSON.stringify(t),e)},t.prototype.startTracker=function(){this.sendAPIMessage(CATEGORY.TRACKER,REQUEST.SET,{push:!0,version:1})},t.prototype.addResponseListener=function(e){this.callbacks.recv=e},t.prototype.disconnect=function(){chrome.sockets.tcp.onReceive.removeListener(this._onReceive),chrome.sockets.tcp.onReceiveError.removeListener(this._onReceiveError),chrome.sockets.tcp.disconnect(this.socketId),chrome.sockets.tcp.close(this.socketId),this.socketId=null,this.isConnected=!1},t.prototype._onCreate=function(e){chrome.runtime.lastError&&o("Unable to create socket: "+chrome.runtime.lastError.message),this.socketId=e.socketId,this.isConnected=!0,chrome.sockets.tcp.connect(this.socketId,this.host,this.port,this._onConnectComplete.bind(this))},t.prototype._onConnectComplete=function(e){return 0>e?void o("Unable to connect to server"):(chrome.sockets.tcp.onReceive.addListener(this._onReceive),chrome.sockets.tcp.onReceiveError.addListener(this._onReceiveError),void(this.callbacks.connect&&this.callbacks.connect()))},t.prototype._onReceive=function(e){e.socketId==this.socketId&&this.callbacks.recv&&this._arrayBufferToString(e.data,function(e){this.callbacks.recv(e)}.bind(this))},t.prototype._onReceiveError=function(e){e.socketId==this.socketId&&o("Unable to receive data from socket: "+e.resultCode)},t.prototype._onSendComplete=function(e){this.callbacks.sent&&this.callbacks.sent(e)},t.prototype._arrayBufferToString=function(e,t){var s=new FileReader;s.onload=function(e){t(e.target.result)};var o=new Blob([e],{type:"application/octet-stream"});s.readAsText(o)},t.prototype._stringToArrayBuffer=function(e,t){var s=new Blob([e]),o=new FileReader;o.onload=function(e){t(e.target.result)},o.readAsArrayBuffer(s)},e.TcpClient=t}(window),function(e){function t(t){this.latestRequestId=1,this.options=c,this.trackerInfo=r,this.callback={},this.apiCallback={},this.frame={smoothXY:{x:0,y:0},deltaTime:0,lastFrameTime:new Date,smoothStatus:{gazing:{value:!1,counter:0},eyes:{value:!1,counter:0},presence:{value:!1,counter:0},fail:{value:!1,counter:0},lost:{value:!1,counter:0}},status:{presence:!1},lefteye:{pcenter:{x:0,y:0}},righteye:{pcenter:{x:0,y:0}},blinkCounter:0,blinkPhase:n.NOT_STARTED},this._onAPIMessageReceived=this._onAPIMessageReceived.bind(this),this.callback.onFrameCallback=t.onFrameCallback,this.callback.onBlinkCallback=t.onBlinkCallback,s=new e.TcpClient(this.options.host,this.options.port),s.addResponseListener(this._onAPIMessageReceived),s.connect(function(e){console.log("EyeTribe Connected"),this.getTrackerInfo(function(e){console.log(e),void 0!=e&&void 0!=e.screen_bounds&&(this.options.nativeScreenX=e.screen_bounds.x,this.options.nativeScreenY=e.screen_bounds.y,this.options.nativeScreenWidth=e.screen_bounds.width,this.options.nativeScreenHeight=e.screen_bounds.height)}.bind(this))}.bind(this))}var s,o={REQUEST:"request",RESPONSE:"response",EVENT:"event"},i={TRACKER:"tracker",CALIBRATION:"calibration"},n={NOT_STARTED:0,BEFORE_EYES_CLOSED:1,EYES_CLOSED:2,AFTER_EYES_CLOSED:3},r={push:!1,version:1,trackerstate:void 0,framerate:30,iscalibrated:!1,iscalibrating:!1,calibresult:void 0,frame:void 0,screenindex:0,screenresw:1024,screenresh:768,screenpsyw:1,screenpsyh:1},c={host:"127.0.0.1",port:6555,smoothingFactor:.9,smoothStatusDelay:100,blinkEyesClosePeriod:1e3,blinkEyesOpenPeriod:50,blinkEyesCloseErrorTolerance:500,nativeScreenWidth:1920,nativeScreenHeight:1280,nativeScreenX:0,nativeScreenY:0};t.prototype._onAPIMessageReceived=function(e){try{if(e=JSON.parse(e),"response"===e.type){if(void 0!=e.requestId){var t=this.apiCallback[e.requestId];"function"==typeof t&&t(e.data)}}else"request"===e.type||"event"===e.type&&"frame"===e.event_type&&(this._processFrame(e.data),this.callback.onFrameCallback(this.frame))}catch(s){console.log(s)}},t.prototype._sendAPIMessage=function(e,t,o,i,n){var r={type:e,resource:t,path:o};if("request"==e){var c=this.latestRequestId++;r.requestId=c,this.apiCallback[c]=n}void 0!=i&&(r.parameters=i),s.sendMessage(JSON.stringify(r))},t.prototype.getTrackerInfo=function(e){this._sendAPIMessage(o.REQUEST,i.TRACKER,"get.basic_info",void 0,e)},t.prototype.requestCalibration=function(e){this._sendAPIMessage(o.REQUEST,i.CALIBRATION,"start",void 0,e)},t.prototype._processFrame=function(e){this.frame.status.presence=e.userPresence,this.frame.deltaTime=new Date-this.frame.lastFrameTime,this.frame.lastFrameTime=new Date,this.frame.nativeScreenWidth=this.options.nativeScreenWidth,this.frame.nativeScreenHeight=this.options.nativeScreenHeight,this.frame.lefteye.pcenter.x=1-e.eyePosition.leftNormalized.x,this.frame.lefteye.pcenter.y=e.eyePosition.leftNormalized.y,this.frame.righteye.pcenter.x=1-e.eyePosition.rightNormalized.x,this.frame.righteye.pcenter.y=e.eyePosition.rightNormalized.y,e.gaze.x=e.gaze.x-this.options.nativeScreenX,e.gaze.y=e.gaze.y-this.options.nativeScreenY;var t=Math.abs(this.frame.smoothXY.x-e.gaze.x),s=Math.abs(this.frame.smoothXY.y-e.gaze.y);Math.sqrt(t*t+s*s);this.frame.smoothXY.x=this.frame.smoothXY.x*this.options.smoothingFactor+e.gaze.x*(1-this.options.smoothingFactor),this.frame.smoothXY.y=this.frame.smoothXY.y*this.options.smoothingFactor+e.gaze.y*(1-this.options.smoothingFactor)},e.TobiiEyeX=t}(window); \ No newline at end of file diff --git a/examples/chromeapp/scripts/eyex-chrome.js b/examples/chromeapp/scripts/eyex-chrome.js index ed24bf5..451f145 100644 --- a/examples/chromeapp/scripts/eyex-chrome.js +++ b/examples/chromeapp/scripts/eyex-chrome.js @@ -1 +1 @@ -!function(e){function t(e,t){this.host=e,this.port=t,this._onReceive=this._onReceive.bind(this),this._onReceiveError=this._onReceiveError.bind(this),this.callbacks={connect:null,disconnect:null,recv:null,sent:null},this.socketId=null,this.isConnected=!1,s("initialized tcp client")}function s(e){console.log(e)}function o(e){console.error(e)}t.prototype.connect=function(e){this.callbacks.connect=e,chrome.sockets.tcp.create({},this._onCreate.bind(this))},t.prototype.sendMessage=function(e,t){this.callbacks.sent=t,this._stringToArrayBuffer(e+"\n",function(e){chrome.sockets.tcp.send(this.socketId,e,this._onSendComplete.bind(this))}.bind(this))},t.prototype.sendAPIMessage=function(e,t,s,o){var i={category:e,request:t,values:s};this.sendMessage(JSON.stringify(i),o)},t.prototype.sendHeartbeat=function(e){var t={category:"heartbeat"};this.sendMessage(JSON.stringify(t),e)},t.prototype.startTracker=function(){this.sendAPIMessage(CATEGORY.TRACKER,REQUEST.SET,{push:!0,version:1})},t.prototype.addResponseListener=function(e){this.callbacks.recv=e},t.prototype.disconnect=function(){chrome.sockets.tcp.onReceive.removeListener(this._onReceive),chrome.sockets.tcp.onReceiveError.removeListener(this._onReceiveError),chrome.sockets.tcp.disconnect(this.socketId),chrome.sockets.tcp.close(this.socketId),this.socketId=null,this.isConnected=!1},t.prototype._onCreate=function(e){chrome.runtime.lastError&&o("Unable to create socket: "+chrome.runtime.lastError.message),this.socketId=e.socketId,this.isConnected=!0,chrome.sockets.tcp.connect(this.socketId,this.host,this.port,this._onConnectComplete.bind(this))},t.prototype._onConnectComplete=function(e){return 0>e?void o("Unable to connect to server"):(chrome.sockets.tcp.onReceive.addListener(this._onReceive),chrome.sockets.tcp.onReceiveError.addListener(this._onReceiveError),void(this.callbacks.connect&&this.callbacks.connect()))},t.prototype._onReceive=function(e){e.socketId==this.socketId&&this.callbacks.recv&&this._arrayBufferToString(e.data,function(e){this.callbacks.recv(e)}.bind(this))},t.prototype._onReceiveError=function(e){e.socketId==this.socketId&&o("Unable to receive data from socket: "+e.resultCode)},t.prototype._onSendComplete=function(e){this.callbacks.sent&&this.callbacks.sent(e)},t.prototype._arrayBufferToString=function(e,t){var s=new FileReader;s.onload=function(e){t(e.target.result)};var o=new Blob([e],{type:"application/octet-stream"});s.readAsText(o)},t.prototype._stringToArrayBuffer=function(e,t){var s=new Blob([e]),o=new FileReader;o.onload=function(e){t(e.target.result)},o.readAsArrayBuffer(s)},e.TcpClient=t}(window),function(e){function t(t){this.latestRequestId=1,this.options=c,this.trackerInfo=r,this.callback={},this.apiCallback={},this.frame={smoothXY:{x:0,y:0},deltaTime:0,lastFrameTime:new Date,smoothStatus:{gazing:{value:!1,counter:0},eyes:{value:!1,counter:0},presence:{value:!1,counter:0},fail:{value:!1,counter:0},lost:{value:!1,counter:0}},status:{presence:!1},lefteye:{pcenter:{x:0,y:0}},righteye:{pcenter:{x:0,y:0}},blinkCounter:0,blinkPhase:n.NOT_STARTED},this._onAPIMessageReceived=this._onAPIMessageReceived.bind(this),this.callback.onFrameCallback=t.onFrameCallback,this.callback.onBlinkCallback=t.onBlinkCallback,this.options.browserScreenWidth=t.browserScreenWidth,this.options.browserScreenHeight=t.browserScreenHeight,s=new e.TcpClient(this.options.host,this.options.port),s.addResponseListener(this._onAPIMessageReceived),s.connect(function(e){console.log("EyeTribe Connected"),this.getTrackerInfo(function(e){console.log(e),void 0!=e&&void 0!=e.screen_bounds&&(this.options.nativeScreenX=e.screen_bounds.x,this.options.nativeScreenY=e.screen_bounds.y,this.options.nativeScreenWidth=e.screen_bounds.width,this.options.nativeScreenHeight=e.screen_bounds.height)}.bind(this))}.bind(this))}var s,o={REQUEST:"request",RESPONSE:"response",EVENT:"event"},i={TRACKER:"tracker",CALIBRATION:"calibration"},n={NOT_STARTED:0,BEFORE_EYES_CLOSED:1,EYES_CLOSED:2,AFTER_EYES_CLOSED:3},r={push:!1,version:1,trackerstate:void 0,framerate:30,iscalibrated:!1,iscalibrating:!1,calibresult:void 0,frame:void 0,screenindex:0,screenresw:1024,screenresh:768,screenpsyw:1,screenpsyh:1},c={host:"127.0.0.1",port:6555,smoothingFactor:.9,smoothStatusDelay:100,blinkEyesClosePeriod:1e3,blinkEyesOpenPeriod:50,blinkEyesCloseErrorTolerance:500,nativeScreenWidth:1920,nativeScreenHeight:1280,nativeScreenX:0,nativeScreenY:0,browserScreenWidth:1280,browserScreenHeight:852};t.prototype._onAPIMessageReceived=function(e){try{if(e=JSON.parse(e),"response"===e.type){if(void 0!=e.requestId){var t=this.apiCallback[e.requestId];"function"==typeof t&&t(e.data)}}else"request"===e.type||"event"===e.type&&"frame"===e.event_type&&(this._processFrame(e.data),this.callback.onFrameCallback(this.frame))}catch(s){console.log(s)}},t.prototype._sendAPIMessage=function(e,t,o,i,n){var r={type:e,resource:t,path:o};if("request"==e){var c=this.latestRequestId++;r.requestId=c,this.apiCallback[c]=n}void 0!=i&&(r.parameters=i),s.sendMessage(JSON.stringify(r))},t.prototype.getTrackerInfo=function(e){this._sendAPIMessage(o.REQUEST,i.TRACKER,"get.basic_info",void 0,e)},t.prototype.requestCalibration=function(e){this._sendAPIMessage(o.REQUEST,i.CALIBRATION,"start",void 0,e)},t.prototype._processFrame=function(e){this.frame.status.presence=e.userPresence,this.frame.deltaTime=new Date-this.frame.lastFrameTime,this.frame.lastFrameTime=new Date,this.frame.lefteye.pcenter.x=1-e.eyePosition.leftNormalized.x,this.frame.lefteye.pcenter.y=e.eyePosition.leftNormalized.y,this.frame.righteye.pcenter.x=1-e.eyePosition.rightNormalized.x,this.frame.righteye.pcenter.y=e.eyePosition.rightNormalized.y,e.gaze.x=(e.gaze.x-this.options.nativeScreenX)*this.options.browserScreenWidth/this.options.nativeScreenWidth,e.gaze.y=(e.gaze.y-this.options.nativeScreenY)*this.options.browserScreenHeight/this.options.nativeScreenHeight;var t=Math.abs(this.frame.smoothXY.x-e.gaze.x),s=Math.abs(this.frame.smoothXY.y-e.gaze.y);Math.sqrt(t*t+s*s);this.frame.smoothXY.x=this.frame.smoothXY.x*this.options.smoothingFactor+e.gaze.x*(1-this.options.smoothingFactor),this.frame.smoothXY.y=this.frame.smoothXY.y*this.options.smoothingFactor+e.gaze.y*(1-this.options.smoothingFactor)},e.TobiiEyeX=t}(window); \ No newline at end of file +!function(e){function t(e,t){this.host=e,this.port=t,this._onReceive=this._onReceive.bind(this),this._onReceiveError=this._onReceiveError.bind(this),this.callbacks={connect:null,disconnect:null,recv:null,sent:null},this.socketId=null,this.isConnected=!1,s("initialized tcp client")}function s(e){console.log(e)}function o(e){console.error(e)}t.prototype.connect=function(e){this.callbacks.connect=e,chrome.sockets.tcp.create({},this._onCreate.bind(this))},t.prototype.sendMessage=function(e,t){this.callbacks.sent=t,this._stringToArrayBuffer(e+"\n",function(e){chrome.sockets.tcp.send(this.socketId,e,this._onSendComplete.bind(this))}.bind(this))},t.prototype.sendAPIMessage=function(e,t,s,o){var i={category:e,request:t,values:s};this.sendMessage(JSON.stringify(i),o)},t.prototype.sendHeartbeat=function(e){var t={category:"heartbeat"};this.sendMessage(JSON.stringify(t),e)},t.prototype.startTracker=function(){this.sendAPIMessage(CATEGORY.TRACKER,REQUEST.SET,{push:!0,version:1})},t.prototype.addResponseListener=function(e){this.callbacks.recv=e},t.prototype.disconnect=function(){chrome.sockets.tcp.onReceive.removeListener(this._onReceive),chrome.sockets.tcp.onReceiveError.removeListener(this._onReceiveError),chrome.sockets.tcp.disconnect(this.socketId),chrome.sockets.tcp.close(this.socketId),this.socketId=null,this.isConnected=!1},t.prototype._onCreate=function(e){chrome.runtime.lastError&&o("Unable to create socket: "+chrome.runtime.lastError.message),this.socketId=e.socketId,this.isConnected=!0,chrome.sockets.tcp.connect(this.socketId,this.host,this.port,this._onConnectComplete.bind(this))},t.prototype._onConnectComplete=function(e){return 0>e?void o("Unable to connect to server"):(chrome.sockets.tcp.onReceive.addListener(this._onReceive),chrome.sockets.tcp.onReceiveError.addListener(this._onReceiveError),void(this.callbacks.connect&&this.callbacks.connect()))},t.prototype._onReceive=function(e){e.socketId==this.socketId&&this.callbacks.recv&&this._arrayBufferToString(e.data,function(e){this.callbacks.recv(e)}.bind(this))},t.prototype._onReceiveError=function(e){e.socketId==this.socketId&&o("Unable to receive data from socket: "+e.resultCode)},t.prototype._onSendComplete=function(e){this.callbacks.sent&&this.callbacks.sent(e)},t.prototype._arrayBufferToString=function(e,t){var s=new FileReader;s.onload=function(e){t(e.target.result)};var o=new Blob([e],{type:"application/octet-stream"});s.readAsText(o)},t.prototype._stringToArrayBuffer=function(e,t){var s=new Blob([e]),o=new FileReader;o.onload=function(e){t(e.target.result)},o.readAsArrayBuffer(s)},e.TcpClient=t}(window),function(e){function t(t){this.latestRequestId=1,this.options=c,this.trackerInfo=r,this.callback={},this.apiCallback={},this.frame={smoothXY:{x:0,y:0},deltaTime:0,lastFrameTime:new Date,smoothStatus:{gazing:{value:!1,counter:0},eyes:{value:!1,counter:0},presence:{value:!1,counter:0},fail:{value:!1,counter:0},lost:{value:!1,counter:0}},status:{presence:!1},lefteye:{pcenter:{x:0,y:0}},righteye:{pcenter:{x:0,y:0}},blinkCounter:0,blinkPhase:n.NOT_STARTED},this._onAPIMessageReceived=this._onAPIMessageReceived.bind(this),this.callback.onFrameCallback=t.onFrameCallback,this.callback.onBlinkCallback=t.onBlinkCallback,s=new e.TcpClient(this.options.host,this.options.port),s.addResponseListener(this._onAPIMessageReceived),s.connect(function(e){console.log("EyeTribe Connected"),this.getTrackerInfo(function(e){console.log(e),void 0!=e&&void 0!=e.screen_bounds&&(this.options.nativeScreenX=e.screen_bounds.x,this.options.nativeScreenY=e.screen_bounds.y,this.options.nativeScreenWidth=e.screen_bounds.width,this.options.nativeScreenHeight=e.screen_bounds.height)}.bind(this))}.bind(this))}var s,o={REQUEST:"request",RESPONSE:"response",EVENT:"event"},i={TRACKER:"tracker",CALIBRATION:"calibration"},n={NOT_STARTED:0,BEFORE_EYES_CLOSED:1,EYES_CLOSED:2,AFTER_EYES_CLOSED:3},r={push:!1,version:1,trackerstate:void 0,framerate:30,iscalibrated:!1,iscalibrating:!1,calibresult:void 0,frame:void 0,screenindex:0,screenresw:1024,screenresh:768,screenpsyw:1,screenpsyh:1},c={host:"127.0.0.1",port:6555,smoothingFactor:.9,smoothStatusDelay:100,blinkEyesClosePeriod:1e3,blinkEyesOpenPeriod:50,blinkEyesCloseErrorTolerance:500,nativeScreenWidth:1920,nativeScreenHeight:1280,nativeScreenX:0,nativeScreenY:0};t.prototype._onAPIMessageReceived=function(e){try{if(e=JSON.parse(e),"response"===e.type){if(void 0!=e.requestId){var t=this.apiCallback[e.requestId];"function"==typeof t&&t(e.data)}}else"request"===e.type||"event"===e.type&&"frame"===e.event_type&&(this._processFrame(e.data),this.callback.onFrameCallback(this.frame))}catch(s){console.log(s)}},t.prototype._sendAPIMessage=function(e,t,o,i,n){var r={type:e,resource:t,path:o};if("request"==e){var c=this.latestRequestId++;r.requestId=c,this.apiCallback[c]=n}void 0!=i&&(r.parameters=i),s.sendMessage(JSON.stringify(r))},t.prototype.getTrackerInfo=function(e){this._sendAPIMessage(o.REQUEST,i.TRACKER,"get.basic_info",void 0,e)},t.prototype.requestCalibration=function(e){this._sendAPIMessage(o.REQUEST,i.CALIBRATION,"start",void 0,e)},t.prototype._processFrame=function(e){this.frame.status.presence=e.userPresence,this.frame.deltaTime=new Date-this.frame.lastFrameTime,this.frame.lastFrameTime=new Date,this.frame.nativeScreenWidth=this.options.nativeScreenWidth,this.frame.nativeScreenHeight=this.options.nativeScreenHeight,this.frame.lefteye.pcenter.x=1-e.eyePosition.leftNormalized.x,this.frame.lefteye.pcenter.y=e.eyePosition.leftNormalized.y,this.frame.righteye.pcenter.x=1-e.eyePosition.rightNormalized.x,this.frame.righteye.pcenter.y=e.eyePosition.rightNormalized.y,e.gaze.x=e.gaze.x-this.options.nativeScreenX,e.gaze.y=e.gaze.y-this.options.nativeScreenY;var t=Math.abs(this.frame.smoothXY.x-e.gaze.x),s=Math.abs(this.frame.smoothXY.y-e.gaze.y);Math.sqrt(t*t+s*s);this.frame.smoothXY.x=this.frame.smoothXY.x*this.options.smoothingFactor+e.gaze.x*(1-this.options.smoothingFactor),this.frame.smoothXY.y=this.frame.smoothXY.y*this.options.smoothingFactor+e.gaze.y*(1-this.options.smoothingFactor)},e.TobiiEyeX=t}(window); \ No newline at end of file diff --git a/src/tobii-eyex-client.js b/src/tobii-eyex-client.js index 657b90d..eb2fbdd 100644 --- a/src/tobii-eyex-client.js +++ b/src/tobii-eyex-client.js @@ -62,9 +62,7 @@ nativeScreenWidth: 1920, nativeScreenHeight: 1280, nativeScreenX: 0, - nativeScreenY: 0, - browserScreenWidth: 1280, - browserScreenHeight: 852 + nativeScreenY: 0 }; @@ -103,8 +101,6 @@ this._onAPIMessageReceived = this._onAPIMessageReceived.bind(this); this.callback.onFrameCallback = options.onFrameCallback; this.callback.onBlinkCallback = options.onBlinkCallback; - this.options.browserScreenWidth = options.browserScreenWidth; - this.options.browserScreenHeight = options.browserScreenHeight; tcpClient = new exports.TcpClient(this.options.host, this.options.port); tcpClient.addResponseListener(this._onAPIMessageReceived); @@ -227,6 +223,8 @@ this.frame.deltaTime = (new Date()) - this.frame.lastFrameTime; this.frame.lastFrameTime = new Date(); + this.frame.nativeScreenWidth = this.options.nativeScreenWidth; + this.frame.nativeScreenHeight = this.options.nativeScreenHeight; //TODO this.frame.lefteye.pcenter.x = 1.0 - frame.eyePosition.leftNormalized.x; this.frame.lefteye.pcenter.y = frame.eyePosition.leftNormalized.y; @@ -242,8 +240,9 @@ // Smooth XY //console.log(this.options); - frame.gaze.x = (frame.gaze.x - this.options.nativeScreenX) * this.options.browserScreenWidth / this.options.nativeScreenWidth; - frame.gaze.y = (frame.gaze.y - this.options.nativeScreenY) * this.options.browserScreenHeight / this.options.nativeScreenHeight; + frame.gaze.x = (frame.gaze.x - this.options.nativeScreenX) + frame.gaze.y = (frame.gaze.y - this.options.nativeScreenY) + var dx = Math.abs(this.frame.smoothXY.x - frame.gaze.x); var dy = Math.abs(this.frame.smoothXY.y - frame.gaze.y);