c37ba162fe6891fee900c81d6aa45192dc267440
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
))
19 on
: (eventName
, fn
) => {
20 if (!events
[eventName
])
21 events
[eventName
] = []
22 events
[eventName
].push(fn
)
24 emit
: (eventName
, data
) =>
25 events
[eventName
] && events
[eventName
].forEach((fn
) => fn(data
))
27 GET
: (location
) => fs
.request(location
, 'GET'),
28 POST
: (location
, data
) => fs
.request(location
, 'POST', data
)
30 //!set up root account (/acct/local)
31 //.make device pseudo-files (/dev/keyboard, /dev/touch, /dev/camera, /dev/audio, ...)
32 //-multiplexed devices: /run/<pid>/keyboard, /run/<pid>/touch, /run/<pid>
33 // (directory whose post/gets are sockets to app)
34 //devices are just web api event forwarders. e.g.:
35 //document.addEventListener('keydown') etcetera -> /dev/keyboard.emit('keydown')
36 //CONNECT adds remote listener? CONNECT gives event emitter (listener) for file
37 // that emits GET/PUT/POST/DEL/etc events. each file has a "connections" list,
38 // which are objects with .send methods (sockets, or an event emitter object
39 // evt emitter object has a fn emit(evt), and .send(evt) -> emit(evt)