Skip to content
This repository has been archived by the owner on Jan 28, 2025. It is now read-only.

Commit

Permalink
fix list device output
Browse files Browse the repository at this point in the history
  • Loading branch information
Dante1349 committed Feb 1, 2022
1 parent 43c3aee commit d7d6a7b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "capacitor-midi",
"version": "0.0.7",
"version": "0.0.8",
"description": "Grants access to midi devices via native libraries or WebMIDI.",
"main": "dist/plugin.cjs.js",
"module": "dist/esm/index.js",
Expand Down
10 changes: 5 additions & 5 deletions src/WebMIDIHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ export class WebMIDIHandler {
}
}

public getInputsAndOutputs(): string[] {
public getInputsAndOutputs(): { value: string[] } {
if (!this.midi) {
console.error("WebMidi not initialized!")
return []
return {value: []}
}

const devices = []
Expand All @@ -59,7 +59,7 @@ export class WebMIDIHandler {
devices.push((entry.name) ? entry.name : "Unknown Device")
}
}
return devices
return {value: devices}
}

public addConnectionListener(callback: (devices: { value: string[] }) => any): void {
Expand All @@ -70,10 +70,10 @@ export class WebMIDIHandler {
this.midi.removeListener("connected")
this.midi.removeListener("disconnected")
this.midi.addListener("connected", () => {
callback({value: this.getInputsAndOutputs()})
callback(this.getInputsAndOutputs())
})
this.midi.addListener("disconnected", () => {
callback({value: this.getInputsAndOutputs()})
callback(this.getInputsAndOutputs())
})
}
}
19 changes: 10 additions & 9 deletions src/definitions.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import type {PluginListenerHandle} from "@capacitor/core";

export interface MIDIPlugin {
listMIDIDevices(): Promise<string[]>
listMIDIDevices(): Promise<{ value: string[] }>

openDevice(options: DeviceOptions): Promise<void>
openDevice(options: DeviceOptions): Promise<void>

initConnectionListener(): Promise<void>
initConnectionListener(): Promise<void>

addListener(eventName: 'MIDI_MSG_EVENT', listenerFunc: (message: MidiMessage) => void): Promise<PluginListenerHandle> & PluginListenerHandle;
addListener(eventName: 'MIDI_CON_EVENT', listenerFunc: (devices: {value: string[]}) => void): Promise<PluginListenerHandle> & PluginListenerHandle;
addListener(eventName: 'MIDI_MSG_EVENT', listenerFunc: (message: MidiMessage) => void): Promise<PluginListenerHandle> & PluginListenerHandle;

addListener(eventName: 'MIDI_CON_EVENT', listenerFunc: (devices: { value: string[] }) => void): Promise<PluginListenerHandle> & PluginListenerHandle;
}

export interface MidiMessage {
type: string;
note: number;
velocity: number;
type: string;
note: number;
velocity: number;
}

export interface DeviceOptions {
deviceNumber: number
deviceNumber: number
}
4 changes: 2 additions & 2 deletions src/web.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { WebPlugin} from '@capacitor/core';
import {WebPlugin} from '@capacitor/core';

import {WebMIDIHandler} from "./WebMIDIHandler";
import type {DeviceOptions, MIDIPlugin} from './definitions';

export class MIDIPluginWeb extends WebPlugin implements MIDIPlugin {
private wmh: WebMIDIHandler = WebMIDIHandler.instance

async listMIDIDevices(): Promise<string[]> {
async listMIDIDevices(): Promise<{ value: string[] }> {
const wmh = WebMIDIHandler.instance;
await wmh.initWebMidi()

Expand Down

0 comments on commit d7d6a7b

Please sign in to comment.