- class StrappFile extends Object {
- constructor(...props) {
- super()
- return Object.assign(this, new.target.defaults, ...props)
- }
- static PermissionDenied() {
- return new Promise((resolve, reject) => reject('Permission denied'))
- }
- static get(path) {
- return localforage.getItem(path)
- }
- static set(path, data) {
- return localforage.setItem(path, data)
- }
- static delete(path) {
- return localforage.removeItem(path)
- }
- HEAD(opt) {
- if (authorize(opt.pubKey, 'r', this.stat))
- return new Promise((resolve, reject) => resolve(''))
- else
- return StrappFile.PermissionDenied()
- }
- GET(opt) {
- if (authorize(opt.pubKey, 'r', this.stat))
- return StrappFile.get(this.path)
- else return StrappFile.PermissionDenied()
- }
- PUT(opt) {
- if (authorize(opt.pubKey, 'w', this.stat))
- return StrappFile.set(this.path, opt.data)
- else return StrappFile.PermissionDenied()
- }
- POST(opt) {
- return this.PUT(Object.assign(opt, { data: this.GET(opt) + opt.data }))
- }
- DELETE(opt) {
- if (authorize(opt.pubKey, 'w', this.stat))
- return StrappFile.delete(this.path)
- else return StrappFile.PermissionDenied()
- }
- OPTIONS(opt) {
- return this.stat
- }
- CONNECT(opt) {
- return this.GET(opt)
- }
- TRACE(opt) {
- }
- PATCH(opt) {
- }
- }
- StrappFile.defaults = {
- stat: {
- type: 'mime/type',
- perm: 0,
- owner: 'thisOwnerPubKey',
- group: 'groupname',
- changed: 'time',
- created: 'time',
- accessed: 'time - not saved'
- }
- }
- return StrappFile
-})()
-
-const StrappPeerConnection = (() => {
- class StrappPeerConnection extends StrappFile {
- GET(opts) {
- //get metadata (held in filesystem), with owner, usage info, etc
- //if unauthed, send message down socket
- }
- PUT(opts) {
- //create w/ sdp, register callback (or pipe), set owner
- }
- POST(opts) {
- //send msg
- }
- CONNECT(opts) {
- //send routing message down socket
- //POST(opts.routemessage)
- }
- }
- return StrappPeerConnection
+ //!set up root account (/acct/local)
+ //.make device pseudo-files (/dev/keyboard, /dev/touch, /dev/camera, /dev/audio, ...)
+ //-multiplexed devices: /run/<pid>/keyboard, /run/<pid>/touch, /run/<pid>
+ // (directory whose post/gets are sockets to app)
+ //devices are just web api event forwarders. e.g.:
+ //document.addEventListener('keydown') etcetera -> /dev/keyboard.emit('keydown')
+ //CONNECT adds remote listener? CONNECT gives event emitter (listener) for file
+ // that emits GET/PUT/POST/DEL/etc events. each file has a "connections" list,
+ // which are objects with .send methods (sockets, or an event emitter object
+ // evt emitter object has a fn emit(evt), and .send(evt) -> emit(evt)