diff --git a/README.md b/README.md index 1369186..459f7a1 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,10 @@ The project is still very young, and more documentation and organization is Comi - [App Structure](#app-structure) - [Metal (@web3os-core/metal)](#metal-web3os-coremetal) - [WebUSB](#webusb) +- [WebHID](#webhid) - [Web Bluetooth](#web-bluetooth) +- [Web Serial](#web-serial) +- [Web MIDI](#web-midi) - [TODO](#todo) - [Can it do *thing*?](#can-it-do-thing) - [Further Documentation](#further-documentation) @@ -606,6 +609,23 @@ Access the array of devices within an app: `await navigator.serial.getPorts()` +# Web MIDI + +
+Expand Web MIDI + +```text +Usage: + midi inputs List MIDI inputs + midi outputs List MIDI outputs + + Options: + --help Print this help message + --version Print the version information +``` + +
+ ## TODO
diff --git a/docs/-_loader.js.html b/docs/-_loader.js.html index 1701b72..61248b1 100644 --- a/docs/-_loader.js.html +++ b/docs/-_loader.js.html @@ -93,7 +93,7 @@ View Source -
+
diff --git a/docs/Web3osTerminal.html b/docs/Web3osTerminal.html index 1a37443..63ed3e6 100644 --- a/docs/Web3osTerminal.html +++ b/docs/Web3osTerminal.html @@ -93,7 +93,7 @@ View Source
-
+
diff --git a/docs/config.js.html b/docs/config.js.html index 97e7537..e94e0f0 100644 --- a/docs/config.js.html +++ b/docs/config.js.html @@ -93,7 +93,7 @@ View Source
-
+
diff --git a/docs/global.html b/docs/global.html index 3f14dfe..29e224e 100644 --- a/docs/global.html +++ b/docs/global.html @@ -93,7 +93,7 @@ View Source
-
+
@@ -2174,7 +2174,7 @@

@@ -3871,7 +3871,7 @@

@@ -4034,7 +4034,7 @@

@@ -4331,7 +4331,7 @@

@@ -4422,7 +4422,7 @@

@@ -4986,7 +4986,7 @@

@@ -5079,7 +5079,7 @@

@@ -5794,7 +5794,7 @@

@@ -6457,7 +6457,7 @@

diff --git a/docs/index.html b/docs/index.html index d67118c..9b1ed2d 100644 --- a/docs/index.html +++ b/docs/index.html @@ -93,7 +93,7 @@ View Source

-
+
@@ -184,7 +184,10 @@
  • App Structure
  • Metal (@web3os-core/metal)
  • WebUSB
  • +
  • WebHID
  • Web Bluetooth
  • +
  • Web Serial
  • +
  • Web MIDI
  • TODO
  • Can it do thing?
  • Further Documentation
  • @@ -623,6 +626,18 @@

    Web Serial

    Access the array of devices within an app: await navigator.serial.getPorts()

    +

    Web MIDI

    +
    +Expand Web MIDI +
    Usage:
    +    midi inputs                       List MIDI inputs
    +    midi outputs                      List MIDI outputs
    +
    +  Options:
    +    --help                            Print this help message
    +    --version                         Print the version information
    +
    +

    TODO

    Expand TODO diff --git a/docs/kernel.js.html b/docs/kernel.js.html index eb41fc5..6babd1b 100644 --- a/docs/kernel.js.html +++ b/docs/kernel.js.html @@ -93,7 +93,7 @@ View Source -
    +
    @@ -193,7 +193,7 @@

    */ export const builtinModules = [ '3pm', 'account', 'backend', 'backup', 'bluetooth', 'confetti', 'contract', 'desktop', 'edit', - 'files', 'gamepad', 'help', 'hid', 'lang', 'peer', 'ping', 'repl', 'screensaver', 'serial', + 'files', 'gamepad', 'help', 'hid', 'lang', 'midi', 'peer', 'ping', 'repl', 'screensaver', 'serial', 'speak', 'socket', 'three', 'usb', 'view', 'vm', 'wallet', 'wasm', 'worker', 'www' ] @@ -869,6 +869,8 @@

    fs.writeFileSync('/proc/platform', navigator.userAgentData.platform) fs.writeFileSync('/proc/querystring', location.search) fs.writeFileSync('/proc/language', navigator.language) + fs.writeFileSync('/proc/user-agent', navigator.userAgent) + fs.writeFileSync('/proc/user-agent.json', JSON.stringify(navigator.userAgentData)) const { downlink, effectiveType, rtt, saveData } = navigator.connection fs.writeFileSync('/proc/connection', JSON.stringify({ downlink, effectiveType, rtt, saveData }, null, 2)) diff --git a/docs/module-@web3os-core_3pm.html b/docs/module-@web3os-core_3pm.html index e006ff9..5ecbe13 100644 --- a/docs/module-@web3os-core_3pm.html +++ b/docs/module-@web3os-core_3pm.html @@ -93,7 +93,7 @@ View Source

    -
    +
    diff --git a/docs/module-@web3os-core__loader.html b/docs/module-@web3os-core__loader.html index d051bf5..e066b92 100644 --- a/docs/module-@web3os-core__loader.html +++ b/docs/module-@web3os-core__loader.html @@ -93,7 +93,7 @@ View Source
    -
    +
    diff --git a/docs/module-@web3os-core_account.html b/docs/module-@web3os-core_account.html index 4e604da..d887da3 100644 --- a/docs/module-@web3os-core_account.html +++ b/docs/module-@web3os-core_account.html @@ -93,7 +93,7 @@ View Source
    -
    +
    diff --git a/docs/module-@web3os-core_peer.html b/docs/module-@web3os-core_peer.html index 58852ad..5d77c60 100644 --- a/docs/module-@web3os-core_peer.html +++ b/docs/module-@web3os-core_peer.html @@ -93,7 +93,7 @@ View Source
    -
    +
    diff --git a/docs/modules_3pm_index.js.html b/docs/modules_3pm_index.js.html index 9b25d6a..34d2fa4 100644 --- a/docs/modules_3pm_index.js.html +++ b/docs/modules_3pm_index.js.html @@ -93,7 +93,7 @@ View Source
    -
    +
    diff --git a/docs/modules_account_index.js.html b/docs/modules_account_index.js.html index 6b4cc1e..d973948 100644 --- a/docs/modules_account_index.js.html +++ b/docs/modules_account_index.js.html @@ -93,7 +93,7 @@ View Source
    -
    +
    diff --git a/docs/modules_peer_index.js.html b/docs/modules_peer_index.js.html index ca6dbea..9138d3d 100644 --- a/docs/modules_peer_index.js.html +++ b/docs/modules_peer_index.js.html @@ -93,7 +93,7 @@ View Source
    -
    +
    diff --git a/docs/terminal_index.js.html b/docs/terminal_index.js.html index ffdd3bd..6152859 100644 --- a/docs/terminal_index.js.html +++ b/docs/terminal_index.js.html @@ -93,7 +93,7 @@ View Source
    -
    +
    diff --git a/docs/tutorial-connect-your-wallet.html b/docs/tutorial-connect-your-wallet.html index 44b9513..b5585eb 100644 --- a/docs/tutorial-connect-your-wallet.html +++ b/docs/tutorial-connect-your-wallet.html @@ -93,7 +93,7 @@ View Source
    -
    +
    diff --git a/src/kernel.js b/src/kernel.js index 1f509e0..b5329ca 100644 --- a/src/kernel.js +++ b/src/kernel.js @@ -72,7 +72,7 @@ export const KernelEvents = [ */ export const builtinModules = [ '3pm', 'account', 'backend', 'backup', 'bluetooth', 'confetti', 'contract', 'desktop', 'edit', - 'files', 'gamepad', 'help', 'hid', 'lang', 'peer', 'ping', 'repl', 'screensaver', 'serial', + 'files', 'gamepad', 'help', 'hid', 'lang', 'midi', 'peer', 'ping', 'repl', 'screensaver', 'serial', 'speak', 'socket', 'three', 'usb', 'view', 'vm', 'wallet', 'wasm', 'worker', 'www' ] @@ -748,6 +748,8 @@ export async function setupFilesystem (initfsUrl, mountableFilesystemConfig) { fs.writeFileSync('/proc/platform', navigator.userAgentData.platform) fs.writeFileSync('/proc/querystring', location.search) fs.writeFileSync('/proc/language', navigator.language) + fs.writeFileSync('/proc/user-agent', navigator.userAgent) + fs.writeFileSync('/proc/user-agent.json', JSON.stringify(navigator.userAgentData)) const { downlink, effectiveType, rtt, saveData } = navigator.connection fs.writeFileSync('/proc/connection', JSON.stringify({ downlink, effectiveType, rtt, saveData }, null, 2)) diff --git a/src/modules/hid/index.js b/src/modules/hid/index.js index 4fec8f2..b2b0669 100644 --- a/src/modules/hid/index.js +++ b/src/modules/hid/index.js @@ -27,7 +27,6 @@ export const help = ` export const spec = { '--help': Boolean, - '--name': String, '--product': String, '--vendor': String, '--version': Boolean diff --git a/src/modules/midi/index.js b/src/modules/midi/index.js new file mode 100644 index 0000000..30b173d --- /dev/null +++ b/src/modules/midi/index.js @@ -0,0 +1,56 @@ +import arg from 'arg' +import colors from 'ansi-colors' +import { parse as cliParse } from 'shell-quote' + +export const name = 'midi' +export const version = '0.1.0' +export const description = 'Web MIDI Utility' +export const help = ` + Usage: + midi inputs List MIDI inputs + midi outputs List MIDI outputs + + Options: + --help Print this help message + --version Print the version information +` + +export const spec = { + '--help': Boolean, + '--version': Boolean +} + +export async function printDevices(type, args) { + const data = [] + const { terminal } = args + + const midi = await navigator.requestMIDIAccess() + + for (const [id, device] of midi[type].entries()) { + const { connection, manufacturer, name, state, type, version } = device + data.push({ id, manufacturer, name, state, connection, type, version }) + } + + terminal.log(JSON.stringify(data, null, 2)) +} + +export async function execute (cmd, args) { + switch (cmd) { + case 'inputs': + return await printDevices('inputs', args) + case 'outputs': + return await printDevices('outputs', args) + default: + return args.terminal.log(help) + } +} + +export async function run (term, context = '') { + if (!navigator.requestMIDIAccess) throw new Error(colors.danger('Client does not support Web MIDI')) + const args = arg(spec, { argv: cliParse(context) }) + if (args['--version']) return term.log(version) + if (args['--help']) return term.log(help) + + args.terminal = term + return execute(args._?.[0], args) +} diff --git a/src/modules/serial/index.js b/src/modules/serial/index.js index 2475a5c..858e718 100644 --- a/src/modules/serial/index.js +++ b/src/modules/serial/index.js @@ -25,7 +25,6 @@ export const help = ` export const spec = { '--help': Boolean, - '--name': String, '--product': String, '--vendor': String, '--version': Boolean