2 * @file Strapp API and initialization driver
3 * @author Jordan Lavatai, Ken Grimes
6 * @copyright August 2017 - Ken Grimes, Jordan Lavatai
9 import fs
from "./strappFileSystem.js"
11 const strapp
= (() => {
14 request
: (location
, method
, data
) => new Promise((resolve
, reject
) => {
15 fs
.request(location
, method
, data
)
16 .then((response
) => resolve(response
))
17 .catch((err
) => reject(err
))
20 on
: (eventName
, fn
) => {
21 if (!events
[eventName
])
22 events
[eventName
] = []
23 events
[eventName
].push(fn
)
25 emit
: (eventName
, data
) =>
26 events
[eventName
] && events
[eventName
].forEach((fn
) => fn(data
))
28 GET
: (location
) => fs
.request(location
, 'GET'),
29 POST
: (location
, data
) => fs
.request(location
, 'POST', data
)
31 //!set up root account (/acct/local)
32 //.make device pseudo-files (/dev/keyboard, /dev/touch, /dev/camera, /dev/audio, ...)
33 //-multiplexed devices: /run/<pid>/keyboard, /run/<pid>/touch, /run/<pid>
34 // (directory whose post/gets are sockets to app)
35 //devices are just web api event forwarders. e.g.:
36 //document.addEventListener('keydown') etcetera -> /dev/keyboard.emit('keydown')
37 //CONNECT adds remote listener? CONNECT gives event emitter (listener) for file
38 // that emits GET/PUT/POST/DEL/etc events. each file has a "connections" list,
39 // which are objects with .send methods (sockets, or an event emitter object
40 // evt emitter object has a fn emit(evt), and .send(evt) -> emit(evt)