topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Saturday December 14, 2024, 2:21 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: plugin/JS communication????  (Read 8628 times)

Coolness

  • Supporting Member
  • Joined in 2009
  • **
  • default avatar
  • Posts: 5
    • View Profile
    • Donate to Member
plugin/JS communication????
« on: July 12, 2009, 01:12 AM »
Hi all,
I know that a plugin can call "EmbeddedWb.ExecJavascript, JAVASCRIPT CALL TO MAKE" and can receive the immediate result via ExecJavascriptResult, but is it possible for a plugin to also receive a farr://string ?

Coolness

  • Supporting Member
  • Joined in 2009
  • **
  • default avatar
  • Posts: 5
    • View Profile
    • Donate to Member
Re: plugin/JS communication????
« Reply #1 on: July 12, 2009, 01:31 AM »
I should also ask...is there a maximum buffer for the JAVASCRIPT CALL TO MAKE?? say I want to send a huge string....
Or the return value?

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,914
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: plugin/JS communication????
« Reply #2 on: July 12, 2009, 01:36 AM »
i think the answer is yes to the first, and for the second, there isnt really a limit i dont think, though dc member ecaradec may know better.

believe it or not.. and this is scary.. but dc members czb and ewemoa know much better than me how to do these fancy fscript farr plugin things,  i'll send them a message to make sure they see this post and reply.

sounds like you are making something fun! care to share some info about what you are planning to do?

ecaradec

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 410
    • View Profile
    • Blog & Projects
    • Read more about this member.
    • Donate to Member
Re: plugin/JS communication????
« Reply #3 on: July 14, 2009, 05:54 AM »
I'm not sure this will fix the issue, but I increased the getStrValue buffer from 4ko to 1Mo. Let me know. There must be a limit since there is no way I can't get the memory I'm going to need.
Mouser, could it be possible to add something to read the length of the data ? Or I could add a parameter to let the plugin tell how much memory it want to allocate. I figure this out as I'm writing, that might be a good solution.
Blog & Projects : Blog | Qatapult | SwiffOut | FScript

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,914
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: plugin/JS communication????
« Reply #4 on: July 14, 2009, 09:40 AM »
Mouser, could it be possible to add something to read the length of the data
Yes i can add that i think.

Note that I think Coolness is wanting to set a large string contents for the web browser, not get it.  I suggested that one way, perhaps the smart way, would be t write the large contents to a file and tell farr to open the file in the browser.  That's what farr does anyway when it comes to displaying a string in the browser.

ecaradec

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 410
    • View Profile
    • Blog & Projects
    • Read more about this member.
    • Donate to Member
Re: plugin/JS communication????
« Reply #5 on: July 14, 2009, 04:42 PM »
Isn't the result received through getStrValue("EmbeddedWb.ExecJavascript")  ? I thought that this buffer was the problem, was it ?
Blog & Projects : Blog | Qatapult | SwiffOut | FScript

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,914
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: plugin/JS communication????
« Reply #6 on: July 14, 2009, 04:49 PM »
hmm you're right, that's what he seems to be saying.

Coolness

  • Supporting Member
  • Joined in 2009
  • **
  • default avatar
  • Posts: 5
    • View Profile
    • Donate to Member
Re: plugin/JS communication????
« Reply #7 on: July 16, 2009, 10:57 AM »
right now I'm just struggling to set up some basic communication.
Say I set the mode to html, tell it to load a file. The html file contains an anchor to farr://sendthisstring. I click it, but no function in my plugin is called (I set up a messagebox on everything). Suggestions?
BOOL MyPlugin_SetStrVal(const char* varname, void *val)
{
   // farr host will pass us function pointer we will call
   if (strcmp(varname,DEF_FieldName_NotifySearchCallbackFp)==0)
      callbackfp_notifysearchstatechanged = (Fp_GlobalPluginCallback_NotifySearchStateChanged)val;
     MessageBox(0,varname,"",0); //nothing about farr:// being clicked.
   return FALSE;
}

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,914
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: plugin/JS communication????
« Reply #8 on: July 16, 2009, 11:28 AM »
i think you'll need to use something like:
 farr://pcommand sendthisstring

then in set_strval check for if varname is pcommand

czb knows how to do this stuff and his plugins make heavy use of it.

Coolness

  • Supporting Member
  • Joined in 2009
  • **
  • default avatar
  • Posts: 5
    • View Profile
    • Donate to Member
Re: plugin/JS communication????
« Reply #9 on: July 16, 2009, 04:33 PM »
Ahh I thought pcommand was something you replace with your plugin name. Gotcha.

Unless I'm doing something wrong, this method of communicating via farr:// and Wb.ExecJavascript doesn't seem to be that robust. For example, a simple test page with
Code: HTML [Select]
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. var timesrun = 0;
  3. function runthis(str)
  4. {
  5.         timesrun++;
  6.         document.getElementById("link").innerHTML = ""+timesrun;
  7.         document.getElementById("link").click();
  8. }
  9.  
  10. <a id="link" onclick="location.href=this.href" href="farr://pcommand RETURN something">Send return signal</a>
  11.  
  12. </body></html>
And then in the plugin
Code: C++ [Select]
  1. BOOL MyPlugin_SetStrVal(const char* varname, void *val)
  2.         {
  3.         // farr host will pass us function pointer we will call
  4.         if (strcmp(varname,DEF_FieldName_NotifySearchCallbackFp)==0)
  5.                 callbackfp_notifysearchstatechanged = (Fp_GlobalPluginCallback_NotifySearchStateChanged)val;
  6.  
  7.         std::string s(varname);
  8.         if (s.find("pcommand",0)!=std::string::npos)
  9.         {
  10.                 MessageBox(0,"Received message from javascript. Calling js function.",varname,0);
  11.                 callbackfp_set_strval(hostptr,"EmbeddedWb.ExecJavascript","runthis('something')");
  12.                 return TRUE;                    
  13.         }
  14.         return FALSE;
  15. }
Then igo [the html page].
Click the link, and at least for me, the link sends the farr:// command 3 times, but the plugin only receives it twice, and the loop isn't infinite as it should be.

I tried adding a delay in case windows doesn't handle executing protocols quickly or something, but to no avail.

I have a backup method with an XMLHttpRequest object if the above method isnt possible, but before I give up with it, any suggestions?

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,914
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: plugin/JS communication????
« Reply #10 on: July 16, 2009, 04:46 PM »
hmm.. i cant think of any reason you shouldnt be able to trigger it as much as you want..
is it possible that the modal blocking MessageBox has something to do with why it's breaking.. maybe try something like a Beep or similar and do put in a second long delay between calls, just to make sure that's not the problem.

if you manually click the link and do away with the loop, does it work or also give you problems about not responding to clicks?

Coolness

  • Supporting Member
  • Joined in 2009
  • **
  • default avatar
  • Posts: 5
    • View Profile
    • Donate to Member
Re: plugin/JS communication????
« Reply #11 on: July 16, 2009, 05:02 PM »
This is getting strange. I removed all MessageBox()s and alert()s. Without a timeout, it stalls at displaying 2, meaning the plugin receives pcommand twice and calls the js twice, but doesnt receive anything after that. If I change line 10 in the JS above to
window.setTimeout( function() { document.getElementById("link").click(); },1000);
I get the numbers every second, in this order: 2 6 14 30 62 126 254 696
So the first 1000 milliseconds it managed two hits, then 4 in the second, then 8 in the third, 16 in the 4th, 32 in the 5th, etc.
2^n? wtf