Discovering EMS availabilility and connected state in the LSR
Reposting Mike Mahoney's blog post:
"There’s two Lua properties in tw_server that you can use to discover information about the EMS's availability and connection status:
- tw_server.available – set to true if the script resource can connect to the EMS.
- tw_server.online – set to true if the script resource detects that the EMS is connected.
Here’s how they work. Everytime the tw_server API is used to make a HTTP request to the EMS it checks the EMS status:
- If the HTTP response is 200, it considers the EMS available and online
- If it is a an error, is calls the new isConnected property
- If the result is a 200:
- Set tw_server.available to true
- Checks the result of the response to set tw_server.online
- If the result is a 503 with a JSON response:
- Set tw_server.available to true
- Checks the result of the response to set tw_server.online
- If the result is a 503 without a JSON response:
- Sets tw_server.available to false
- Sets tw_server.online to false
- If the result is a 200:
Keep in mind that these variables can be stale if the LSR has not recently communicated with the EMS. However, the LSR does ping the EMS periodically (every 60 seconds by default) to ensure that it is still available."
