0

I was trying to adapt the jsfiddle example given at the Affectiva developer site:

https://jsfiddle.net/affectiva/opyh5e8d/show/

I added the html section from the fiddle into an html file and the js script separately into a js file and called it in the html file.

Pressing start on the jsfiddle shows multiple logs and a popup requesting permission to use the camera. But my local example did not do so. Debugging with some console logs, I narrowed it down to one line that was not getting executed in the affdex.js (the sdk provided js file) script code:

require(docElement, url, function() {
self._startCamera();
},
function() {
self.getCallback("onInitialize", false)("Unable to load adaptor.js to load the camera"); 

which is inside this code block from affdex.js:

self.start = function() {
if(!self.isRunning) {
ctor();
var url = affdex.getAffdexDotJsLocation() + adapterJSVersion;
require(docElement, url, function() {
self._startCamera();
},
function() {
self.getCallback("onInitialize", false)("Unable to load adaptor.js to load the camera");
});
}
};

This question has been asked before at :Affdex JS SDK - Can't get callbacks from the camera detector So I took the answer suggested there and tried running it and inspecting the console logs and got the error:

"Failed to load resource: the http://localhost:8000/affdex/adapter-1.4.0.js server responded with a status of 404 (File not found)"

which is effectively what the "require.." line of code eventually tries to load. It looks like its a dependency but it was not listed in the jsfiddle and I am not able to find it anywhere on the Affectiva SDK site either.

If anyone has an idea about this, any help would be appreciated. Thanks.

som.g
  • 3
  • 3

2 Answers2

3

If you really need to be able to run it without Internet access, it works if you download all these files and keep them in the same place as affdex.js

  • affdex.js
  • affdex-worker.js
  • affdex-native-bindings.js.mem
  • affdex-native-bindings.js
  • affdex-native-bindings.data
  • affdex-native-bindings.asm.js
  • adapter-1.4.0.js
redolent
  • 61
  • 4
1

affdex.js pulls a bunch of dependencies from our CDN including adaptor.js, which is why you can't host it yourself. You have to use hosted version instead. In your HTML file change

<script src="http://localhost:8000/affdex/affdex.js" type="text/javascript"> </script>

to

<script src="https://download.affectiva.com/js/3.1/affdex.js" type="text/javascript"> </script>
ahamino
  • 634
  • 1
  • 4
  • 12