Showing
4 changed files
with
45 additions
and
68 deletions
1 | arcs_module(function (ARCS) { | 1 | arcs_module(function (ARCS) { |
2 | var Inertial = ARCS.Component.create( function() { | 2 | var Inertial = ARCS.Component.create( function() { |
3 | var self = this; | 3 | var self = this; |
4 | + var screenOrientation = false; | ||
4 | 5 | ||
6 | + // here, we should correct orientation | ||
5 | var handleOrientation = function (event) { | 7 | var handleOrientation = function (event) { |
8 | + if (screenOrientation) { | ||
9 | + var orientation = screen.msOrientation | ||
10 | + || screen.mozOrientation || screen.orientation; | ||
11 | + event.alpha -= (orientation)?orientation.angle:0; | ||
12 | + } | ||
6 | self.emit("sendOrientation",event); | 13 | self.emit("sendOrientation",event); |
7 | }; | 14 | }; |
8 | 15 | ||
... | @@ -17,7 +24,6 @@ arcs_module(function (ARCS) { | ... | @@ -17,7 +24,6 @@ arcs_module(function (ARCS) { |
17 | if (window.DeviceOrientationEvent) { | 24 | if (window.DeviceOrientationEvent) { |
18 | console.log("Device orientation capability detected"); | 25 | console.log("Device orientation capability detected"); |
19 | window.addEventListener("deviceorientation", handleOrientation, false); | 26 | window.addEventListener("deviceorientation", handleOrientation, false); |
20 | - //window.ondeviceorientation = handleOrientation; | ||
21 | } else { | 27 | } else { |
22 | console.log("[Inertial]","no device orientation API"); | 28 | console.log("[Inertial]","no device orientation API"); |
23 | } | 29 | } |
... | @@ -31,9 +37,13 @@ arcs_module(function (ARCS) { | ... | @@ -31,9 +37,13 @@ arcs_module(function (ARCS) { |
31 | 37 | ||
32 | 38 | ||
33 | }; | 39 | }; |
40 | + | ||
41 | + this.setScreenOrientation = function(flag) { | ||
42 | + screenOrientation = flag; | ||
43 | + }; | ||
34 | 44 | ||
35 | }, | 45 | }, |
36 | - ["start"], | 46 | + ["start","setScreenOrientation"], |
37 | ["sendOrientation","sendAcceleration","sendAccelerationIncludingGravity", "sendRotationRate"] | 47 | ["sendOrientation","sendAcceleration","sendAccelerationIncludingGravity", "sendRotationRate"] |
38 | ); | 48 | ); |
39 | 49 | ||
... | @@ -42,4 +52,4 @@ arcs_module(function (ARCS) { | ... | @@ -42,4 +52,4 @@ arcs_module(function (ARCS) { |
42 | 52 | ||
43 | 53 | ||
44 | return { Inertial : Inertial }; | 54 | return { Inertial : Inertial }; |
45 | -}); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
55 | +}); | ... | ... |
... | @@ -12,6 +12,8 @@ arcs_module(function(ARCS) { | ... | @@ -12,6 +12,8 @@ arcs_module(function(ARCS) { |
12 | video.src = window.webkitURL.createObjectURL(stream); | 12 | video.src = window.webkitURL.createObjectURL(stream); |
13 | } else if (video.mozSrcObject !== undefined) { | 13 | } else if (video.mozSrcObject !== undefined) { |
14 | video.mozSrcObject = stream; | 14 | video.mozSrcObject = stream; |
15 | + } else if (video.srcObject !== undefined) { | ||
16 | + video.srcObject = stream; | ||
15 | } else { | 17 | } else { |
16 | video.src = stream; | 18 | video.src = stream; |
17 | } | 19 | } |
... | @@ -126,4 +128,4 @@ arcs_module(function(ARCS) { | ... | @@ -126,4 +128,4 @@ arcs_module(function(ARCS) { |
126 | 128 | ||
127 | 129 | ||
128 | return {LiveSource: LiveSource, VideoSource: VideoSource}; | 130 | return {LiveSource: LiveSource, VideoSource: VideoSource}; |
129 | -}); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
131 | +}); | ... | ... |
1 | +import ARCS from './arcs.js'; | ||
2 | + | ||
3 | + | ||
1 | /** | 4 | /** |
2 | * Bootstrap for the ARCS engine in a browser environment. | 5 | * Bootstrap for the ARCS engine in a browser environment. |
3 | * It relies on require.js to get the job done. | 6 | * It relies on require.js to get the job done. |
... | @@ -23,25 +26,23 @@ xhr.onerror = function (e) { | ... | @@ -23,25 +26,23 @@ xhr.onerror = function (e) { |
23 | console.error("[ARCS] Failed to get app description (",appDescription,"):",e.target.status,e.message); | 26 | console.error("[ARCS] Failed to get app description (",appDescription,"):",e.target.status,e.message); |
24 | }; | 27 | }; |
25 | 28 | ||
26 | -require(['arcs'], function (ARCS) { | 29 | +xhr.onreadystatechange = function() { |
27 | - //console.log(ARCS); | 30 | + if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) { |
28 | - xhr.onreadystatechange = function() { | 31 | + try { |
29 | - if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) { | 32 | + console.log("ARCS application description loaded"); |
30 | - try { | 33 | + var applicationObject = JSON.parse(xhr.responseText); |
31 | - console.log("ARCS application description loaded"); | 34 | + if (baseUrl) { |
32 | - var applicationObject = JSON.parse(xhr.responseText); | 35 | + // TODO change this line below |
33 | - if (baseUrl) { | 36 | + require.config( { baseUrl: baseUrl }); |
34 | - require.config( { baseUrl: baseUrl }); | ||
35 | - } | ||
36 | - var aap = new ARCS.Application(); | ||
37 | - aap.import(applicationObject); | ||
38 | - console.log("Starting application..."); | ||
39 | - aap.start(); | ||
40 | - } catch (e) { | ||
41 | - console.error("[ARCS] Error while parsing JSON:",e); | ||
42 | } | 37 | } |
38 | + var aap = new ARCS.Application(); | ||
39 | + aap.import(applicationObject); | ||
40 | + console.log("Starting application..."); | ||
41 | + aap.start(); | ||
42 | + } catch (e) { | ||
43 | + console.error("[ARCS] Error while parsing JSON:",e); | ||
43 | } | 44 | } |
44 | - }; | 45 | + } |
46 | +}; | ||
45 | 47 | ||
46 | - xhr.send(); | 48 | +xhr.send(); |
47 | -}); | ... | ... |
... | @@ -8,25 +8,27 @@ | ... | @@ -8,25 +8,27 @@ |
8 | * @param deps {mixed[]} dependencies | 8 | * @param deps {mixed[]} dependencies |
9 | */ | 9 | */ |
10 | 10 | ||
11 | +// TODO remove dependency handling | ||
12 | + | ||
13 | + | ||
11 | // reimplementation using native promises | 14 | // reimplementation using native promises |
12 | -arcs_module = function(moduleDefinition, deps) { | 15 | +arcs_module = function(moduleDefinition) { |
13 | var storeComponents, i; | 16 | var storeComponents, i; |
14 | 17 | ||
18 | + // TODO verify if this is still needed | ||
15 | if (typeof module !== 'undefined') { | 19 | if (typeof module !== 'undefined') { |
16 | if (module.parent.exports) { | 20 | if (module.parent.exports) { |
17 | ARCS = module.exports; | 21 | ARCS = module.exports; |
18 | } | 22 | } |
19 | } | 23 | } |
20 | 24 | ||
21 | - if (deps === undefined) { deps = []; } | ||
22 | 25 | ||
23 | - storeComponents = function (deps) { | 26 | + storeComponents = function () { |
24 | var mdef, p; | 27 | var mdef, p; |
25 | // we should insert ARCS at the beginning of deps ! | 28 | // we should insert ARCS at the beginning of deps ! |
26 | - deps.unshift(ARCS); | ||
27 | 29 | ||
28 | mdef = (typeof moduleDefinition === 'function') ? | 30 | mdef = (typeof moduleDefinition === 'function') ? |
29 | - moduleDefinition.apply(this, deps) : moduleDefinition; | 31 | + moduleDefinition.apply(this) : moduleDefinition; |
30 | 32 | ||
31 | if (mdef === undefined) { | 33 | if (mdef === undefined) { |
32 | throw new Error("[ARCS] Your module is undefined. Did you forget to export components?\nCode of module follows:\n" +moduleDefinition); | 34 | throw new Error("[ARCS] Your module is undefined. Did you forget to export components?\nCode of module follows:\n" +moduleDefinition); |
... | @@ -42,49 +44,11 @@ arcs_module = function(moduleDefinition, deps) { | ... | @@ -42,49 +44,11 @@ arcs_module = function(moduleDefinition, deps) { |
42 | }; | 44 | }; |
43 | // until now, it is the very same code. | 45 | // until now, it is the very same code. |
44 | 46 | ||
45 | - // here we create a promise to solve dependency | ||
46 | - // reject has the dependency name, while resolve has the object | ||
47 | - var depResolve = function(dep) { | ||
48 | - return new Promise(function(resolve, reject) { | ||
49 | - var d,shimConfig; | ||
50 | - if (ARCS.isInNode()) { | ||
51 | - d = require(dep); | ||
52 | - if (d === undefined) { | ||
53 | - reject(dep); | ||
54 | - } else { | ||
55 | - resolve(d); | ||
56 | - } | ||
57 | - } else { | ||
58 | - // this one a little bit trickier since we have to shim. | ||
59 | - if (dep.name !== undefined) { | ||
60 | - shimConfig = { shim: {} }; | ||
61 | - shimConfig.shim[dep.name] = { exports: dep.exports }; | ||
62 | - if (dep.deps !== undefined) { | ||
63 | - shimConfig.shim[dep.name].deps = dep.deps; | ||
64 | - } | ||
65 | - require.config(shimConfig); | ||
66 | - dep = dep.name; | ||
67 | - } | ||
68 | - // shim performed | ||
69 | - require([dep], | ||
70 | - function(d) { resolve(d); }, | ||
71 | - function(err) { console.log("[ARCS] Trouble with module ", dep); reject(dep, err); } | ||
72 | - ); | ||
73 | - } | ||
74 | - }); | ||
75 | - }; | ||
76 | - | ||
77 | - var depResolves = []; | ||
78 | - for (i=0; i<deps.length; i++) { | ||
79 | - depResolves[i] = depResolve(deps[i]); | ||
80 | - } | ||
81 | - | ||
82 | - | ||
83 | 47 | ||
84 | ARCS.Context.currentContext.addLibraryPromise( | 48 | ARCS.Context.currentContext.addLibraryPromise( |
85 | - Promise.all(depResolves).then(storeComponents, | 49 | + storeComponents, |
86 | function(reason) { console.error("[ARCS] Failed to load dependency ", reason ); }) | 50 | function(reason) { console.error("[ARCS] Failed to load dependency ", reason ); }) |
87 | 51 | ||
88 | ); | 52 | ); |
89 | 53 | ||
90 | -} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
54 | +} | ... | ... |
-
Please register or login to post a comment