Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #35743 > unrolled thread

Catching event from message alert box, and wait until resolved?

Started byJonas Thörnvall <jonas.thornvall@gmail.com>
First post2018-10-07 10:06 -0700
Last post2018-10-08 08:09 -0700
Articles 11 — 2 participants

Back to article view | Back to comp.lang.javascript


Contents

  Catching event from message alert box, and wait until resolved? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-10-07 10:06 -0700
    Re: Catching event from message alert box, and wait until resolved? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-10-07 16:12 -0700
    Re: Catching event from message alert box, and wait until resolved? JJ <jj4public@vfemail.net> - 2018-10-08 11:45 +0700
      Re: Catching event from message alert box, and wait until resolved? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-10-07 22:58 -0700
        Re: Catching event from message alert box, and wait until resolved? JJ <jj4public@vfemail.net> - 2018-10-10 05:39 +0700
          Re: Catching event from message alert box, and wait until resolved? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-10-09 21:50 -0700
            Re: Catching event from message alert box, and wait until resolved? JJ <jj4public@vfemail.net> - 2018-10-11 20:40 +0700
              Re: Catching event from message alert box, and wait until resolved? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-10-11 15:11 -0700
                Re: Catching event from message alert box, and wait until resolved? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-10-14 20:56 -0700
      Re: Catching event from message alert box, and wait until resolved? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-10-07 23:13 -0700
        Re: Catching event from message alert box, and wait until resolved? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-10-08 08:09 -0700

#35743 — Catching event from message alert box, and wait until resolved?

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-10-07 10:06 -0700
SubjectCatching event from message alert box, and wait until resolved?
Message-ID<6a7727a4-fc96-4366-94aa-4f2b502b64a4@googlegroups.com>
I am trying to get my sequenser to handle sysex messages. The procedure is pretty simple 
if (navigator.requestMIDIAccess) {
  navigator.requestMIDIAccess(
      {sysex: true} //Yeah it is just to set sysex : true
    )
    .then(success, failure);
}

Problem is that the sysex : true generate a message box event. that have to be answered.

file: /// wants to use your midi device

But the program runs on so it gets success and try to read in ports, but apparently the midiobject is not accessible until the alert box event answered.

How can i sidestep that problem or somehow wait for the alert box to be closed, because i guess that is the problem with the ports within midiobjects not accessible. Works fine when sysex false.

[toc] | [next] | [standalone]


#35745

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-10-07 16:12 -0700
Message-ID<f7c2bb16-a05a-4361-abe5-5e062a0858e8@googlegroups.com>
In reply to#35743
Den söndag 7 oktober 2018 kl. 19:06:57 UTC+2 skrev Jonas Thörnvall:
> I am trying to get my sequenser to handle sysex messages. The procedure is pretty simple 
> if (navigator.requestMIDIAccess) {
>   navigator.requestMIDIAccess(
>       {sysex: true} //Yeah it is just to set sysex : true
>     )
>     .then(success, failure);
> }
> 
> Problem is that the sysex : true generate a message box event. that have to be answered.
> 
> file: /// wants to use your midi device
> 
> But the program runs on so it gets success and try to read in ports, but apparently the midiobject is not accessible until the alert box event answered.
> 
> How can i sidestep that problem or somehow wait for the alert box to be closed, because i guess that is the problem with the ports within midiobjects not accessible. Works fine when sysex false.

One start to think that Javascript may not be doing so good nowadays when it is practically impossible to find working examples.

If anyone find a working example of sysex true that manage to list ports, do not hesitate to post the link, and we will see if i can decipher the convoluted code structure.

[toc] | [prev] | [next] | [standalone]


#35746

FromJJ <jj4public@vfemail.net>
Date2018-10-08 11:45 +0700
Message-ID<17wmx6hu6z8kn.lq8ggse14t2a$.dlg@40tude.net>
In reply to#35743
On Sun, 7 Oct 2018 10:06:51 -0700 (PDT), Jonas Thörnvall wrote:
> I am trying to get my sequenser to handle sysex messages. The procedure is
> pretty simple 
> if (navigator.requestMIDIAccess) {
>   navigator.requestMIDIAccess(
>       {sysex: true} //Yeah it is just to set sysex : true
>     )
>     .then(success, failure);
> }
> 
> Problem is that the sysex : true generate a message box event. that have
> to be answered. 
> 
> file: /// wants to use your midi device 

That message box is part of the web browser security system. It can't be
bypassed unless the site in added into the allow list.

> But the program runs on so it gets success and try to read in ports, but
> apparently the midiobject is not accessible until the alert box event
> answered. 

`requestMIDIAccess()` is an asynchronous method. If the script tries to
access the resource without waiting for the resourse to be available, then
it's guaranteed to fail.

> How can i sidestep that problem or somehow wait for the alert box to be
> closed, because i guess that is the problem with the ports within
> midiobjects not accessible. Works fine when sysex false.

You're asking about hacking a security system. The answer would obviously be
no.

[toc] | [prev] | [next] | [standalone]


#35747

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-10-07 22:58 -0700
Message-ID<cbd614d4-8ace-4c8d-ab3a-c14e09cc52f3@googlegroups.com>
In reply to#35746
Den måndag 8 oktober 2018 kl. 06:45:35 UTC+2 skrev JJ:
> On Sun, 7 Oct 2018 10:06:51 -0700 (PDT), Jonas Thörnvall wrote:
> > I am trying to get my sequenser to handle sysex messages. The procedure is
> > pretty simple 
> > if (navigator.requestMIDIAccess) {
> >   navigator.requestMIDIAccess(
> >       {sysex: true} //Yeah it is just to set sysex : true
> >     )
> >     .then(success, failure);
> > }
> > 
> > Problem is that the sysex : true generate a message box event. that have
> > to be answered. 
> > 
> > file: /// wants to use your midi device 
> 
> That message box is part of the web browser security system. It can't be
> bypassed unless the site in added into the allow list.
> 
> > But the program runs on so it gets success and try to read in ports, but
> > apparently the midiobject is not accessible until the alert box event
> > answered. 
> 
> `requestMIDIAccess()` is an asynchronous method. If the script tries to
> access the resource without waiting for the resourse to be available, then
> it's guaranteed to fail.

Well that is my question JJ how do i build the "structure" accesspath so that it wait for user input to get ready.

Right now i load "the main script" like list ports, via HTML function body onLoad. The access part midiaccess.js is loaded in HTML file.

But of course when i read in the HTML file it first import midiaccess.js, but right after it start to load main, before the user have the chance to answer the alert box. So how can i have the HTML body onLoad main.js wait for user input? 

 
> > How can i sidestep that problem or somehow wait for the alert box to be
> > closed, because i guess that is the problem with the ports within
> > midiobjects not accessible. Works fine when sysex false.
> 
> You're asking about hacking a security system. The answer would obviously be
> no.

No i just want to wait for the user to handle the alert box, i want to wait for user input before loading the "main program that call listports" that use the midiaccess object that is not ready.

Lets say this is my midiaccess file, how can i list ports after, the alert box been resolved. So how do i know when the alert box resolved, where do i call the listports(); or alternatively how do i wait until alert box resolved?

Thanks JJ

if (navigator.requestMIDIAccess) {
  navigator.requestMIDIAccess(
     {sysex: false}
   )
  .then(success,failure );
}

function failure() {
  console.error('No access to your midi devices.' + +msg)
}

function success(midi) {
  mid = midi;
  inputs = midi.inputs.values();
  // inputs outputs are Iterators
  for (input = inputs.next(); input && !input.done; input = inputs.next()) {
    // each time there is a midi message call the onMIDIMessage function
    console.log(input);
    input.value.onmidimessage = onMIDIMessage;
  }
}


function listPorts() {
  // Grab an array of all available devices
  var iter = mid.outputs.values();
  for (var i = iter.next(); i && !i.done; i = iter.next()) {
    outportarr.push(i.value);
  }
  PORTout = outportarr[outportindex];

  //List ports in and out
  Lportout = mid.outputs.values();
  Lportin = mid.inputs.values();
  for (listinput = Lportin.next(); listinput && !listinput.done; listinput = Lportin.next()) {
    var deviceIn = listinput.value.name;
    var optin = document.createElement("option");
    optin.text = deviceIn;
    document.getElementById("in_portsel").add(optin);
  }
  for (listoutput = Lportout.next(); listoutput && !listoutput.done; listoutput = Lportout.next()) {
    var deviceOut = listoutput.value.name;
    var optout = document.createElement("option");
    optout.text = deviceOut;
    document.getElementById("out_portsel").add(optout);
  }
}

[toc] | [prev] | [next] | [standalone]


#35761

FromJJ <jj4public@vfemail.net>
Date2018-10-10 05:39 +0700
Message-ID<ecpvs1p333k8.1qiknxcrg9e1t$.dlg@40tude.net>
In reply to#35747
On Sun, 7 Oct 2018 22:58:12 -0700 (PDT), Jonas Thörnvall wrote:
> 
> No i just want to wait for the user to handle the alert box, i want to
> wait for user input before loading the "main program that call listports"
> that use the midiaccess object that is not ready. 
> 
> Lets say this is my midiaccess file, how can i list ports after, the
> alert box been resolved. So how do i know when the alert box resolved,
> where do i call the listports(); or alternatively how do i wait until
> alert box resolved?

The the arguments passed to the `then()` method is the result of the MIDI
access request. It'll succeed if the user allow it, or it'll rejected if
otherwise. By the time any is executed, the confirmation box has been
responded by user. In your case, call `listPorts()` during or after
`success()` is executed.

[toc] | [prev] | [next] | [standalone]


#35765

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-10-09 21:50 -0700
Message-ID<a671a29d-7bc4-4a2d-9c80-993263c64854@googlegroups.com>
In reply to#35761
Den onsdag 10 oktober 2018 kl. 00:39:38 UTC+2 skrev JJ:
> On Sun, 7 Oct 2018 22:58:12 -0700 (PDT), Jonas Thörnvall wrote:
> > 
> > No i just want to wait for the user to handle the alert box, i want to
> > wait for user input before loading the "main program that call listports"
> > that use the midiaccess object that is not ready. 
> > 
> > Lets say this is my midiaccess file, how can i list ports after, the
> > alert box been resolved. So how do i know when the alert box resolved,
> > where do i call the listports(); or alternatively how do i wait until
> > alert box resolved?
> 
> The the arguments passed to the `then()` method is the result of the MIDI
> access request. It'll succeed if the user allow it, or it'll rejected if
> otherwise. By the time any is executed, the confirmation box has been
> responded by user. In your case, call `listPorts()` during or after
> `success()` is executed.

Well weither it is correct or not  i tried to move the main(); call into the success method. It was not a good idea. Because for some reason then the alertbox "dialog" "allow block" is no longer ready, but open. Probably the script try to load resources after success that will not be available until i answered the alert box.

It seem to be a catch 22 situation.

[toc] | [prev] | [next] | [standalone]


#35772

FromJJ <jj4public@vfemail.net>
Date2018-10-11 20:40 +0700
Message-ID<60j1df13403c$.1qep2v2qab88z$.dlg@40tude.net>
In reply to#35765
On Tue, 9 Oct 2018 21:50:13 -0700 (PDT), Jonas Thörnvall wrote:
> 
> Well weither it is correct or not  i tried to move the main(); call into
> the success method. It was not a good idea. Because for some reason then
> the alertbox "dialog" "allow block" is no longer ready, but open.

As long as MIDI access hasn't been granted, MIDI resources are not
available.

> Probably the script try to load resources after success that will not be
> available until i answered the alert box.

How come you don't know your own code?

[toc] | [prev] | [next] | [standalone]


#35776

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-10-11 15:11 -0700
Message-ID<7d06dea8-dafa-4c61-9206-f4388fdd3faf@googlegroups.com>
In reply to#35772
Den torsdag 11 oktober 2018 kl. 15:40:33 UTC+2 skrev JJ:
> On Tue, 9 Oct 2018 21:50:13 -0700 (PDT), Jonas Thörnvall wrote:
> > 
> > Well weither it is correct or not  i tried to move the main(); call into
> > the success method. It was not a good idea. Because for some reason then
> > the alertbox "dialog" "allow block" is no longer ready, but open.
> 
> As long as MIDI access hasn't been granted, MIDI resources are not
> available.
> 
> > Probably the script try to load resources after success that will not be
> > available until i answered the alert box.
> 
> How come you don't know your own code?

I don't think that is the problem as long you have not pushed allow or block resources not available, and the error is not recoverable.

But i am not as fast clicking as the computer throwing up the window. What i do want is wait call main until alert resolved. But i do not know how to know when alert resolved, how do i know and call main after "block or unblock".

[toc] | [prev] | [next] | [standalone]


#35784

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-10-14 20:56 -0700
Message-ID<13e941d0-53c7-4eee-9f06-3bb80e556c34@googlegroups.com>
In reply to#35776
Den fredag 12 oktober 2018 kl. 00:11:57 UTC+2 skrev Jonas Thörnvall:
> Den torsdag 11 oktober 2018 kl. 15:40:33 UTC+2 skrev JJ:
> > On Tue, 9 Oct 2018 21:50:13 -0700 (PDT), Jonas Thörnvall wrote:
> > > 
> > > Well weither it is correct or not  i tried to move the main(); call into
> > > the success method. It was not a good idea. Because for some reason then
> > > the alertbox "dialog" "allow block" is no longer ready, but open.
> > 
> > As long as MIDI access hasn't been granted, MIDI resources are not
> > available.
> > 
> > > Probably the script try to load resources after success that will not be
> > > available until i answered the alert box.
> > 
> > How come you don't know your own code?
> 
> I don't think that is the problem as long you have not pushed allow or block resources not available, and the error is not recoverable.
> 
> But i am not as fast clicking as the computer throwing up the window. What i do want is wait call main until alert resolved. But i do not know how to know when alert resolved, how do i know and call main after "block or unblock".

Well sysex on should probably somehow be invoked at later stage, because only needed when dump from what i understand. So then the question become can you change state of it? How, it is not available after midiaccess success?

[toc] | [prev] | [next] | [standalone]


#35748

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-10-07 23:13 -0700
Message-ID<8a52ba75-e3b3-4fd3-828c-6530b945096b@googlegroups.com>
In reply to#35746
Den måndag 8 oktober 2018 kl. 06:45:35 UTC+2 skrev JJ:
> On Sun, 7 Oct 2018 10:06:51 -0700 (PDT), Jonas Thörnvall wrote:
> > I am trying to get my sequenser to handle sysex messages. The procedure is
> > pretty simple 
> > if (navigator.requestMIDIAccess) {
> >   navigator.requestMIDIAccess(
> >       {sysex: true} //Yeah it is just to set sysex : true
> >     )
> >     .then(success, failure);
> > }
> > 
> > Problem is that the sysex : true generate a message box event. that have
> > to be answered. 
> > 
> > file: /// wants to use your midi device 
> 
> That message box is part of the web browser security system. It can't be
> bypassed unless the site in added into the allow list.
> 
> > But the program runs on so it gets success and try to read in ports, but
> > apparently the midiobject is not accessible until the alert box event
> > answered. 
> 
> `requestMIDIAccess()` is an asynchronous method. If the script tries to
> access the resource without waiting for the resourse to be available, then
> it's guaranteed to fail.
> 
> > How can i sidestep that problem or somehow wait for the alert box to be
> > closed, because i guess that is the problem with the ports within
> > midiobjects not accessible. Works fine when sysex false.
> 
> You're asking about hacking a security system. The answer would obviously be
> no.

One could think of it like this we create another function  that main that will  wait for the alert box to get resolved. Let us call it waitAlertBox(); from the we will call our "main.js which call listport function.

Now the question become how do we know the state of the alert box? I have no idea have you? It must have some property value "resolved true or false"?

[toc] | [prev] | [next] | [standalone]


#35751

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2018-10-08 08:09 -0700
Message-ID<92bacfaf-f76d-4c15-b750-95c14d8adbc2@googlegroups.com>
In reply to#35748
Den måndag 8 oktober 2018 kl. 08:14:06 UTC+2 skrev Jonas Thörnvall:
> Den måndag 8 oktober 2018 kl. 06:45:35 UTC+2 skrev JJ:
> > On Sun, 7 Oct 2018 10:06:51 -0700 (PDT), Jonas Thörnvall wrote:
> > > I am trying to get my sequenser to handle sysex messages. The procedure is
> > > pretty simple 
> > > if (navigator.requestMIDIAccess) {
> > >   navigator.requestMIDIAccess(
> > >       {sysex: true} //Yeah it is just to set sysex : true
> > >     )
> > >     .then(success, failure);
> > > }
> > > 
> > > Problem is that the sysex : true generate a message box event. that have
> > > to be answered. 
> > > 
> > > file: /// wants to use your midi device 
> > 
> > That message box is part of the web browser security system. It can't be
> > bypassed unless the site in added into the allow list.
> > 
> > > But the program runs on so it gets success and try to read in ports, but
> > > apparently the midiobject is not accessible until the alert box event
> > > answered. 
> > 
> > `requestMIDIAccess()` is an asynchronous method. If the script tries to
> > access the resource without waiting for the resourse to be available, then
> > it's guaranteed to fail.
> > 
> > > How can i sidestep that problem or somehow wait for the alert box to be
> > > closed, because i guess that is the problem with the ports within
> > > midiobjects not accessible. Works fine when sysex false.
> > 
> > You're asking about hacking a security system. The answer would obviously be
> > no.
> 
> One could think of it like this we create another function  that main that will  wait for the alert box to get resolved. Let us call it waitAlertBox(); from the we will call our "main.js which call listport function.
> 
> Now the question become how do we know the state of the alert box? I have no idea have you? It must have some property value "resolved true or false"?

Well i will put in on hold, most functionality of synth is reachable without. I think it is only the dumprequests needing sysex, and thereby the file dialog. So one probably just open sysex when dumping data.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web