Using the PerspectiveClient websocket

Hello All,

After a bit of poking around I found a way to utilize the browser PerspectiveClient to instantiate my own javascript Client and use its underlying websocket to receive push data in my iframe.

let w = new window.parent.window.PerspectiveClient.Client({projectName: 'my_dashboard',projectTitle: 'My Dashboard',platformEdition: 'standard'});

while(!w.store.connection.webSocket){
   console.log('waiting for websocket');
   await self.delay(1000);
}     

w.store.subscribeToSessionProps();	

w.store.connection.webSocket.addEventListener('message', async function(m){
   console.log('websocket message:', m);
   if (m.data && m.data.indexOf('client-value-update:') === 0){
   		await self.checkDataQueue();                      
   }
});

This allows me to have receive realtime notifications when my custom session properties change. I use this to alert the browser that data has changed and it needs to re-query.

My question: While this seems to be working well and does exactly what I need, I don’t see any documentation about using the javascript client-side apis like this. Is this supported or is there a more conventional out-of-the-box way to achieve this type of push to the browser without developing my own module?

1 Like

No, not at all.

The only "blessed" approach to doing anything client-side in Perspective is a module with your own components/code.

Gotcha. Fair enough. I found another “creative” workaround by binding the class of the iframe to my data change timestamp. From there I use a javascript mutation observer to watch the class name for changes. Still hacky but works.

It would be nice if the iframe component had some generic way to bind data or maybe an onValueChange event that allowed you to call a javascript method on the iframe’s window when specified tags or properties change. Otherwise you have to set up WebDev endpoints and poll for data (which is so 2012) or write your own module which is non-trivial.