- Create a Perspective page url with a ClientID parameter as follows:
- Then create a view parameter with the same name on your view:
- I binding mine to a text box for visibility:
- Create a messageHandler on a Perspective component, that will be used to recieve the data from vision. In my case I made it a simplelabel, that will receive the data and put it in the text property. Note that it is session scoped.
#Check to make sure that the call is coming from the same Vision Client
#The URL implicitly converts numbers to a string, so its best to cast it that way for comparison
if str(payload['ClientID']) == str(self.view.params.ClientID):
self.props.text = payload['SentText']
-
Set the gateway scripting project to the name of your project, so that the gateway knows where the upcoming Gateway Message Handler is located
-
Create a gateway message handler that looks through each session, and sends the message to each.
clientId = payload['ClientID']
text = payload['Text']
#Define your message payload
payloadDict = {"ClientID":clientId, "SentText":text}
#Gather all perspective sessions
sessionList = system.perspective.getSessionInfo()
#For each perspective session
for session in sessionList:
#Ignore the designer
if session['userAgent'] != "<designer>":
#Grab your SessionID
sessionId = session['id']
#Look at all open pages
for page in session['pageIds']:
system.perspective.sendMessage(messageType="RecieveVisionData", scope="session", payload=payloadDict, sessionId=sessionId, pageId=page)
- Create a project script that will give you your Vision Client ID (To put it in a binding later on)
def getClientID():
return str(system.util.getClientId())
- Create an expression binding on your web browsers URL to navigate to the correct perspective session, and append your client ID to the end of the URL
"http://localhost/data/perspective/client/Vision_To_Perspective_Sync/Test/" + runScript("PerspectiveSync.getClientID()")
- Create a button and text field component, to create some data and trigger a call to the perspective session with the following script:
clientID = system.util.getClientId()
text = event.source.parent.getComponent('Text Field').text
payloadDict = {"ClientID":clientID, "Text":text}
system.util.sendMessage(project="Vision_To_Perspective_Sync", messageHandler="PerspectiveMessage", payload=payloadDict)
- Open a vision client, type some text in, and watch it appear in perspective!
You can scale this as needed for your project with the map radius, the only critical item being passed around here is the ClientID. If you are using authentication in perspective, you could also probably make this a bit more efficient by passing the gateway event a username, and filtering the system.perspective.getSessionInfo() with a username parameter.
This was an interesting little challenge, originally I mentioned using a project script but I was unaware that scripts called there execute in the scope of the originator. Meaning that because we’d be calling it from a Vision client, than it would execute in the Vision Client scope and wouldn’t have access to any of the system.perspective functions needed. That is why I switched to a gateway event handler.
Here is an export of the project as well, if that works out for you let me know, and I will go ahead and put it on the exchange for others as well.
Vision_To_Perspective_Sync_20200616083646.zip (17.8 KB)