SDK transfert data from gateway to perspective

You don’t restrict the UserScopeMessageEvent - you just drill down into the required event bus. From an InternalSession, you can either findPage(<pageid>) or listPages() - then if you want to send a page scoped event, use the page’s event bus: getPageEventBus().

It looks like there’s no complementary function (that’s public) on Page, but sending a ‘View’ scope event would follow a similar model - you need to get to the View you want, then access its event bus.

1 Like

Thanks a lot for these clarifications :+1:

Hi @PGriffith

to obtain the sessionId

String sessionId = InternalSession.SESSION.get().getSession().getSessionId().toString();

work fine.

But if I need to obtain the pageId, I’ve tried:

String pageId = InternalSession.SESSION.get().getSession().getPage().getId().toString();

or

String pageId = InternalSession.SESSION.get().getPage().getId().toString();

But both of them are triggering a java.lang.NullPointerException: null

Did I missed something ?

I try to guess in a script function the sessionId and pageId to keep distinct data for multiple sessionId/pageId.

getPage() on a Session object will always return null. A Session may have multiple pages, so you may have to use getPages(), but I’m not sure if there is a way to know which page is open or whatever it is you are looking for.

Yes session have multiple page, but I try to obtain the “context” (sessionId,pageId) in a module script function.
For sessionId,

String sessionId = InternalSession.SESSION.get().getSession().getSessionId().toString();

but to obtain the current pageId from where the script is executed, I don’t see ?

I want to avoid to pass the pageId parameter to each script function…

Try com.inductiveautomation.perspective.gateway.model.PageModel.PAGE.get().

Just a guess… I’m not very familiar with this area.

1 Like

That’s fine.
:+1: