Toggle navigation
Toggle navigation
This project
Loading...
Sign in
arcs
/
arcs.js
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
3
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Jean-Yves Didier
2019-12-10 09:49:53 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
b38b88309e719e60ec3299483b3e8cb613bb7cdb
b38b8830
1 parent
322c966a
modifications on components
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
68 deletions
components/inertial.js
components/video.js
src/arcs_browser.js
src/arcs_module.js
components/inertial.js
View file @
b38b883
arcs_module
(
function
(
ARCS
)
{
var
Inertial
=
ARCS
.
Component
.
create
(
function
()
{
var
self
=
this
;
var
screenOrientation
=
false
;
// here, we should correct orientation
var
handleOrientation
=
function
(
event
)
{
if
(
screenOrientation
)
{
var
orientation
=
screen
.
msOrientation
||
screen
.
mozOrientation
||
screen
.
orientation
;
event
.
alpha
-=
(
orientation
)?
orientation
.
angle
:
0
;
}
self
.
emit
(
"sendOrientation"
,
event
);
};
...
...
@@ -17,7 +24,6 @@ arcs_module(function (ARCS) {
if
(
window
.
DeviceOrientationEvent
)
{
console
.
log
(
"Device orientation capability detected"
);
window
.
addEventListener
(
"deviceorientation"
,
handleOrientation
,
false
);
//window.ondeviceorientation = handleOrientation;
}
else
{
console
.
log
(
"[Inertial]"
,
"no device orientation API"
);
}
...
...
@@ -31,9 +37,13 @@ arcs_module(function (ARCS) {
};
this
.
setScreenOrientation
=
function
(
flag
)
{
screenOrientation
=
flag
;
};
},
[
"start"
],
[
"start"
,
"setScreenOrientation"
],
[
"sendOrientation"
,
"sendAcceleration"
,
"sendAccelerationIncludingGravity"
,
"sendRotationRate"
]
);
...
...
@@ -42,4 +52,4 @@ arcs_module(function (ARCS) {
return
{
Inertial
:
Inertial
};
});
\ No newline at end of file
});
...
...
components/video.js
View file @
b38b883
...
...
@@ -12,6 +12,8 @@ arcs_module(function(ARCS) {
video
.
src
=
window
.
webkitURL
.
createObjectURL
(
stream
);
}
else
if
(
video
.
mozSrcObject
!==
undefined
)
{
video
.
mozSrcObject
=
stream
;
}
else
if
(
video
.
srcObject
!==
undefined
)
{
video
.
srcObject
=
stream
;
}
else
{
video
.
src
=
stream
;
}
...
...
@@ -126,4 +128,4 @@ arcs_module(function(ARCS) {
return
{
LiveSource
:
LiveSource
,
VideoSource
:
VideoSource
};
});
\ No newline at end of file
});
...
...
src/arcs_browser.js
View file @
b38b883
import
ARCS
from
'./arcs.js'
;
/**
* Bootstrap for the ARCS engine in a browser environment.
* It relies on require.js to get the job done.
...
...
@@ -23,25 +26,23 @@ xhr.onerror = function (e) {
console
.
error
(
"[ARCS] Failed to get app description ("
,
appDescription
,
"):"
,
e
.
target
.
status
,
e
.
message
);
};
require
([
'arcs'
],
function
(
ARCS
)
{
//console.log(ARCS);
xhr
.
onreadystatechange
=
function
()
{
if
(
xhr
.
readyState
==
4
&&
(
xhr
.
status
==
200
||
xhr
.
status
==
0
))
{
try
{
console
.
log
(
"ARCS application description loaded"
);
var
applicationObject
=
JSON
.
parse
(
xhr
.
responseText
);
if
(
baseUrl
)
{
require
.
config
(
{
baseUrl
:
baseUrl
});
}
var
aap
=
new
ARCS
.
Application
();
aap
.
import
(
applicationObject
);
console
.
log
(
"Starting application..."
);
aap
.
start
();
}
catch
(
e
)
{
console
.
error
(
"[ARCS] Error while parsing JSON:"
,
e
);
xhr
.
onreadystatechange
=
function
()
{
if
(
xhr
.
readyState
==
4
&&
(
xhr
.
status
==
200
||
xhr
.
status
==
0
))
{
try
{
console
.
log
(
"ARCS application description loaded"
);
var
applicationObject
=
JSON
.
parse
(
xhr
.
responseText
);
if
(
baseUrl
)
{
// TODO change this line below
require
.
config
(
{
baseUrl
:
baseUrl
});
}
var
aap
=
new
ARCS
.
Application
();
aap
.
import
(
applicationObject
);
console
.
log
(
"Starting application..."
);
aap
.
start
();
}
catch
(
e
)
{
console
.
error
(
"[ARCS] Error while parsing JSON:"
,
e
);
}
};
}
};
xhr
.
send
();
});
xhr
.
send
();
...
...
src/arcs_module.js
View file @
b38b883
...
...
@@ -8,25 +8,27 @@
* @param deps {mixed[]} dependencies
*/
// TODO remove dependency handling
// reimplementation using native promises
arcs_module
=
function
(
moduleDefinition
,
deps
)
{
arcs_module
=
function
(
moduleDefinition
)
{
var
storeComponents
,
i
;
// TODO verify if this is still needed
if
(
typeof
module
!==
'undefined'
)
{
if
(
module
.
parent
.
exports
)
{
ARCS
=
module
.
exports
;
}
}
if
(
deps
===
undefined
)
{
deps
=
[];
}
storeComponents
=
function
(
deps
)
{
storeComponents
=
function
()
{
var
mdef
,
p
;
// we should insert ARCS at the beginning of deps !
deps
.
unshift
(
ARCS
);
mdef
=
(
typeof
moduleDefinition
===
'function'
)
?
moduleDefinition
.
apply
(
this
,
deps
)
:
moduleDefinition
;
moduleDefinition
.
apply
(
this
)
:
moduleDefinition
;
if
(
mdef
===
undefined
)
{
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) {
};
// until now, it is the very same code.
// here we create a promise to solve dependency
// reject has the dependency name, while resolve has the object
var
depResolve
=
function
(
dep
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
var
d
,
shimConfig
;
if
(
ARCS
.
isInNode
())
{
d
=
require
(
dep
);
if
(
d
===
undefined
)
{
reject
(
dep
);
}
else
{
resolve
(
d
);
}
}
else
{
// this one a little bit trickier since we have to shim.
if
(
dep
.
name
!==
undefined
)
{
shimConfig
=
{
shim
:
{}
};
shimConfig
.
shim
[
dep
.
name
]
=
{
exports
:
dep
.
exports
};
if
(
dep
.
deps
!==
undefined
)
{
shimConfig
.
shim
[
dep
.
name
].
deps
=
dep
.
deps
;
}
require
.
config
(
shimConfig
);
dep
=
dep
.
name
;
}
// shim performed
require
([
dep
],
function
(
d
)
{
resolve
(
d
);
},
function
(
err
)
{
console
.
log
(
"[ARCS] Trouble with module "
,
dep
);
reject
(
dep
,
err
);
}
);
}
});
};
var
depResolves
=
[];
for
(
i
=
0
;
i
<
deps
.
length
;
i
++
)
{
depResolves
[
i
]
=
depResolve
(
deps
[
i
]);
}
ARCS
.
Context
.
currentContext
.
addLibraryPromise
(
Promise
.
all
(
depResolves
).
then
(
storeComponents
,
storeComponents
,
function
(
reason
)
{
console
.
error
(
"[ARCS] Failed to load dependency "
,
reason
);
})
);
}
\ No newline at end of file
}
...
...
Please
register
or
login
to post a comment