As suggested in another thread, I’m trying to use the message passing mechanism to communicate from a perspective client to the gateway.
On the client, I’ve set up the following startup and shutdown event scripts:
# startup
system.util.sendMessage(project = 'myproject', messageHandler = 'start_session', payload = { "session_id": session.props.id, "device_id": session.props.device.identifier})
# shutdown
system.util.sendMessage(project = 'myproject', messageHandler = 'end_session', payload = { "session_id": session.props.id, "device_id": session.props.device.identifier})
On the gateway, I’m just logging that the message is being received:
# start_session handler
log = system.util.logger("Gateway Script Logger")
log.info("START SESSION, ID: %s, DEVICE ID: %s" % (payload["session_id"], payload["device_id"]))
# end_session handler
log = system.util.logger("Gateway Script Logger")
log.info("END SESSION, ID: %s, DEVICE ID: %s" % (payload["session_id"], payload["device_id"]))
Now, I launch the perspective session in the browser from designer, and in the logs I see:
Socket connected to session. pageId=2471ea92
START SESSION, ID: 0aed7b35-3fd4-40bd-b360-5719c8a9b552, DEVICE ID:
(not sure about the empty device id). I close the browser, and in the logs I do NOT see the end session event, instead I only see:
WebSocket disconnected from session.
If I relaunch the session, again I do NOT see the start session event, but just:
Socket connected to session. pageId=1e672231
and the same if I continue to launche/close the session. Only after some time (presumably due to timeout) do I see the end session event in the log:
END SESSION, ID: 0aed7b35-3fd4-40bd-b360-5719c8a9b552, DEVICE ID: browser-cd3e7e56-e24e-40a8-9358-bdf7e508071c
(not sure why the device id now appears). Is this expected behavior? I was thinking that I would see a “start_session” event each time I launch a session.