Using JET API's publish and subscribe methods to communicate between two windows in the same app

I have an application that opens to a main window: Window 1. If you click a button in the app, a new window will open: Window 2.

From what I can tell, Window 1 and Window 2 do not share a JET component. E.g., if I store something in JET Archive in Window 1, then open Window 2, Window 2 won't be able to grab the item from JET Archive, because it has its own, empty JET Archive.

I would like to be able to communicate between the two windows. E.g., if I click on a button in Window 2, I want Window 1 to do something in response.

I know I can use JET Context Change to update linked Eikon windows by registering a RIC change. But is there a way to use publish and subscribe to communicate between Window 2 and Window 1?

Right now, I've got this code linked to a button in Window 2:

JET.publish('test', 'Test publish message');

And this code in Window 1:

JET.subscribe("test", this._publishCallBack);  

_publishCallBack: function(){
console.debug("inside publishCallBack, arguments = ", arguments);
}

But when I press the button in Window 2, nothing happens in the console in Window 1.

Have I set this up wrong? Or is what I have in mind just not possible?

Thanks for any help you can provide!

Best Answer

Answers

  • Hi @mbarr, can you try this code that I have?

    	JET.subscribe("/jetplayground", function(message, channel) {
    console.log("From Channel: '"+channel+"' Data: "+message);
    });

    JET.publish("/jetplayground", "From PUB app");

    Above code is working on my side.

  • Hi Panit.

    I copied your code exactly, but it still is not working.

    When you say it is working on your side, are you running the first line in window 1 of an app and then second line in window 2 generated from window 1?

  • They are in the separate window but should also working on the same window as well. The next thing to check is what's the URL you're running this page. Is it localhost? This API is only working with localhost or white-listed domain.

  • They are in the separate window but should also working on the same window as well. The next thing to check is what's the URL you're running this page. Is it localhost? This API is only working with localhost or white-listed domain.

  • I am running this on what should be white-listed urls. The app is otherwise able to use JET API just fine, and the app has been on the TR/Eikon store for months now.

  • Can you try the same code in localhost? There's also a JET test page at cpurl://apps.cp./apps/jetplayground

    You can try this API in the app, choose Publish/Subsribe sample from the catalog. If it's working in jetplayground but not working on yours, I'm quite sure that it's blocked by the URL.

  • When i run the Publish/Subscribe sample, I have two windows, but the message from the pub app is not showing up in the sub app. It's behaving just like what I was trying in my app. The published message is not getting picked up by the subscriber. Could the exact version of JET API be a factor?

  • Did you click "Run" at the subscribe window as well?

  • image.png

    Here is an image from when I run the Publish/Subscribe sample. Should I be seeing something?

  • I added an image in an answer below. Yes, I clicked run in both windows.

  • Can you try to put cpurl://apps.cp./apps/jetplayground in the main search box? You seems to be running it from the 3rd party container. If it's working in the standard window (popup from entering the url from the seach box), it means this API is limited to only TR applications.

  • Yeah, I never see the "From Channel" messages in the subscriber window. Even after I click Run and wait 3+ seconds.

  • Can you try to put cpurl://apps.cp./apps/jetplayground in the main search box? You seems to be running it from the 3rd party container. If it's working in the standard window (popup from entering the url from the seach box), it means this API is limited to only TR applications.

  • Ah! Yes, it is working when I run it out of the main search box, but not out of the Dev one. Does this mean our 3rd party app won't be able to use Publish/Subscribe? Or just I won't be able to test it in the Dev environment?

  • I'll ask the owner of 3rd party container to confirm on this thread on Monday. It's likely to me that this API is limited to only TR app.

  • Great! Appreciate all your efforts on this and the quick, thorough replies. Have a good weekend!

  • Great! Appreciate all your efforts on this and the quick, thorough replies. Have a good weekend!

  • Just wanted to make sure that the pub-sub API is limited to only the TR app. If not, would love to be able to make use of it in our app.

  • Any word on whether pub-sub is usable outside the TR app?

  • Sorry for delay response. I've just got the confirmation from the container team that only localhost or whitelisted urls are allowed. So that means the url you're using is not whitelisted. If you let me know the url, I can do the checking.