views:

1287

answers:

8

Hi,

I have a web application that processes events and audio received from a specialised microphone. The audio is processed by a Java applet that runs in the web page, but other events (microphone connected, microphone disconnected, microphone button pressed) are handled by an ActiveX object.

The ActiveX object traps these events and calls JavaScript code to handle them

<!-- Load the ActiveX control -->
<object id="PhilipsSpeechMikeCtrl" width="0" height="0" tabindex="-1"
    classid="CLSID:AAA44754-CC81-4692-91AF-7064E58EB22A"
    standby="Loading Philips SpeechMike component..."
    type="application/x-oleobject">
</object>

<script type="text/javascript">
    // This is Microsofts javascript way of trapping ActiveX object events.

    function PhilipsSpeechMikeCtrl::SPMEventDeviceConnected(deviceID) {
        // Call JavaScript code to handle the microphone connected event
    }

    function PhilipsSpeechMikeCtrl::SPMEventDeviceDisconnected(deviceID) {
        // Call JavaScript code to handle the microphone disconnected event
    }

    function PhilipsSpeechMikeCtrl::SPMEventButton(deviceID, eventId) {
        // Call JavaScript code to handle the microphone button pressed event
    }
</script>

Of course a problem with this approach is that it's completely IE dependent. I would prefer to load the ActiveX object within the applet, trap the events there and handle the events either within the applet, or JavaScript code called from the applet. This should then enable me to run the app in any browser that supports applets.

I'm not entirely sure how to go about implementing the solution I've proposed above, any suggestions?

Update: I realise the solution I've proposed above would still be IE dependent, that's fine. My immediate goal is to support all browsers on Windows.

It has been suggested that instead of using ActiveX, I could use JNI (or JNA) to access the DLLs underlying the ActiveX object. However, I don't actually want to call the functions in the DLLs, I want the DLLs to call me, i.e. register an event handler.

Thanks, Don

A: 

Wouldn't that still be Windows- or even IE-dependent, given that Java applets are executed on the client side? Just wondering...

Lucas Jones
I've updated the original post
Don
OK. Sorry, I don't know how to help you then. :-)
Lucas Jones
+4  A: 

ActiveX are not supported by an another browser than IE, so there is no way for your application to support all browsers, even on Windows only. An attempt (plugin) to port ActiveX under Firefox 1 was made, but wasn't really useful so as far as I know, there is today no "emulation" solution to your question. Sorry... (see here for Mozilla comments)

Olivier
ActiveX is not supported in other browsers, but Java is. You can call ActiveX from Java.
sjbotha
+2  A: 

You can probably access the dlls in the activeX component directly, so you can write a jni wrapper that calls the native functions, and then build a signed applet that can get permission to use jni.

Check this:

http://www.raditha.com/java/jni/

KarlP
+1  A: 

Ahh. You can do want you desire, but may have to eschew Javascript and instead leverage VBScript. It is about the ability to send "events" between two components.

jm04469
Isn't VBScript only supported in IE?
Don
+1  A: 

You can use use JavaScript to directly call public methods in the applet or access public variables. JavaScript treats the embedded applet as an object. In the applet tag give the applet a name id.

Consider the example below where the applet has a method public void myMethodInMyApplet();

The HTML page would look something like :

<APPLET CODE="MyApplet.class" 
   width=200 height=200 
   name=counter ID=counter>
</APPLET>

<script type="text/javascript">
    // This is Microsofts javascript way of trapping ActiveX object events.

    function PhilipsSpeechMikeCtrl::SPMEventDeviceConnected(deviceID) {
document.applets[0].myMethodInMyApplet();   
 }
 </script>
Paul Whelan
The events that I need to trap are raised by the ActiveX control embedded in the page, not the Applet
Don
Could you then in these events call the javascript methods you define that call the applets public methods?
Paul Whelan
+2  A: 

JACOB is supposed to let you call COM from Java. It looks like it supports events too.

sjbotha
A: 

You will obviously have to pass the events twice if you want them to end up in JavaScript.

There is a version of SWT that can be used in applets and can embed ActiveX controls. There are also commercial libraries like Coroutine who can do this as well (and are smaller in jar size). Someone else mentioned JACOB here, which would be another choice.

So, use any of these components to wrap your ActiveX control. These libraries will call a Java method when a registered event occurs.

To pass events from Java to JavaScript, you can use the netscape.javascript.JSObject class which is supported by all major browsers.

If you have the source code for the COM component, it might be a good idea to rewrite it to use JNI, as COM wrappers use up a lot of resources (which is especially important in applets), and most probably there is also some overhead inside the COM component for COM interop.

mihi
A: 

is activexobjects always hitting the acivex sites like activex.microsoft.com