xrsh-com/helloworld.js

51 lines
2.4 KiB
JavaScript
Raw Normal View History

2023-11-01 12:53:18 +01:00
AFRAME.registerComponent('helloworld', {
2023-11-03 10:57:46 +01:00
schema: { },
2023-11-01 12:53:18 +01:00
2023-11-03 10:57:46 +01:00
init: function () {
2023-11-01 12:53:18 +01:00
2023-11-03 11:07:34 +01:00
// entrypoint for single-file xrshell/AFRAME components
this.addEventListener('xrshell', (opts) => {
2023-11-03 11:24:17 +01:00
this.require = AFRAME.components.xrshell.require // available by adding <a-scene xrshell>
2023-11-03 11:08:59 +01:00
2023-11-03 11:24:17 +01:00
this.require({
2023-11-03 10:57:46 +01:00
"superclipboard": { required: false, repo: "https://github.com/Utopiah/aframe-components" },
2023-11-03 11:07:34 +01:00
"spatialeditor": { required: false, repo: "https://github.com/coderofsalvation/xrshell-apps" },
"jsonform": { required: false, repo: "https://github.com/coderofsalvation/xrshell-apps" },
2023-11-03 10:57:46 +01:00
"speech-controls": { required: false, url: "https://rawgit.com/Utopiah/aframe-speech-controls-component/master/dist/aframe-speech-controls-component.min.js"},
2023-11-03 11:24:17 +01:00
"context-menu": { required: false },
2023-11-03 10:57:46 +01:00
"ISOterminal": { required: false }
})
// the components above get saved cached/to the browser (IndexedDB) filesystem (so the ISOterminal can read/edit them as well in realtime)
2023-11-03 11:07:34 +01:00
// when a required component cannot be included, then this (helloworld) component will be removed and
// errors will show up in the javascript browser and XR terminal consoles.
2023-11-03 10:57:46 +01:00
})
2023-11-01 12:53:18 +01:00
2023-11-03 11:07:34 +01:00
this.addEventListener('ISOterminal', (term) => { // act when component gets mounted
2023-11-03 10:57:46 +01:00
// 'term' is basically AFRAME.components.ISOterminal
term.write('hello to XR linux terminal from AFRAME')
term.on('stdout', (data) => {
2023-11-01 12:53:18 +01:00
// react to data being spoken/typed into the terminal
// (spatial prompting like 'open foo.gltf', 'component helloworld' e.g.)
})
})
2023-11-03 11:24:17 +01:00
this.addEventListener('context-menu', (menu) => {
menu.add({
2023-11-03 10:57:46 +01:00
name: 'edit', // "everything must have an edit-button" ~ Fabien Benetou
icon: 'gear', // see https://jsonforms.io to see json-2-html forms
type: 'object', // json-2-webxr has nothing like it (yet) but offers uniform interfaces across components
properties:{
2023-11-03 11:24:17 +01:00
enabled: { type: 'boolean', default: true, format: 'checkbox' },
edit_terminal: { type: 'function', cb: () => AFRAME.components.ISOterminal.exec('pico /com/helloworld.js') },
edit_spatial: { type: 'function', cb: () => this.require({"spatial-edit":{required:true}}) }
2023-11-03 10:57:46 +01:00
}
2023-11-03 11:24:17 +01:00
})
2023-11-03 10:57:46 +01:00
})
2023-11-01 12:58:37 +01:00
console.log("hello world!")
2023-11-03 10:57:46 +01:00
}
2023-11-01 12:53:18 +01:00
});