WebSockets Guide

WebSockets allow you to retrieve real-time data or prevent you from pulling too many data.

 

When should I use WebSockets?

 

Use WebSockets when pulling data would be too resource-consuming or not "real-time" enough. After a successful connection, the client starts receiving messages depending on the configuration of the Connector API integration in Mews App. You can find all needed information about our WebSockets solution in our documentation, and Mews' requests limits in our guide.

 

 

Can I test WebSockets in Demo?

 

Yes, you can configure and test WebSockets in the Mews Demo environment.

 

Testing with credentials

 

The simplest way to test WebSocket connections would be to use a browser extension. For example, the Browser WebSocket Client Chrome extension.

 

Just as you need a pair of Access and Client tokens to make various API calls to Mews, you need the same to authenticate a WebSocket connection. The Client token corresponds to that of the generic "Are you ready to integrate with Mews?" integration in Mews Demo.

 

For the purposes of testing, you do not need to add a new integration. Instead, use the pair of tokens listed in the Authentication section of our Connector API documentation.

 

Follow the URL format prescribed in the Endpoint part of the WebSockets documentation to set up the connection.

 

Maintaining the connection

Mews recommends that the integration sends a WebSocket Ping request to Mews at regular intervals (e.g., every 5 minutes) to monitor the connection. If the Ping request fails, the integration interface should be restarted or try to re-establish a connection.

 

Types of events you can test

Depending on what the integration does, you may wish to test any of the four types of WebSocket events listed in the API Documentation.

Make any changes to the relevant items in Mews (e.g., reservation, space, rate price, etc.) in order to trigger an event.

 

What it looks like in the production environment

When your integration has been successfully certified with Mews Marketplace, you receive one unique Client Token for your integration, for the production environment, this is to be paired with the Access Token (which differs from property to property).

 

For each property that adds integration to their Marketplace subscriptions, a new Access Token is generated, and it is unique to the specific property. You can then use the pair of Access/Client tokens to establish a WebSocket connection between the property's Mews environment and your integration interface.

 

(Guide for properties on how to find their Access Tokens)

 

 

Testing without credentials

 

If you are mainly interested in the type and content of the WebSocket notification that are generated by a particular event in Mews, you can test WebSockets without the need to configure a connection.

 

  1. Go to dashboard and open the devs tools for Chrome (F12).

  2. Click on "Network" and then select "WS".

  3. Reload the page if needed and you will see the WebSocket in the list.

  4. Click on it and select the tab "Messages". From there you can see all the WebSocket events.

  5. When you make an action that triggers an event, you see it listed there as "Type":"Events", and you can click on it to see its details.

 

If you are able to connect to the WebSocket but do not see any events coming in, make any action in the Mews demo hotel you are connected to, to trigger an event. E.g., create a reservation, check in a reservation, make a space as Inspected, etc.

 

Recommendations on WebSockets implementation

 

One WebSocket instance per Access Token: Integration partners should create separate instances of WebSocket clients for each access token.

Add a time buffer between connecting and reconnecting: Helpful if the WebSocket reconnect keeps failing. 

 

In our Mews Connector application, which also uses WebSockets, Mews starts with an interval between 5 to 30 seconds, and then with each unsuccessful reconnect we add another 5 to 30 seconds on top of that until the maximum interval of 2 minutes is reached. Once a successful connection is established, the app resets the reconnect interval back to the base value.

The connection could drop when we deploy something to the production environment, so try waiting a few minutes before reconnecting.

 

 

Does Mews always send "close" event when the connection is closed?

 

When Mews is the one explicitly closing, yes. This could happen with an unauthorized client throttling (too many requests in a short time) or server instance shutdown.

 

But there are many reasons why WebSockets get closed and WebSockets can drop without notification. Mews doesn't implement any explicit heartbeat solution. The NET component should support the standard Ping/Pong solution via standard opcodes.

 

The Ping/Pong solution

 

The interface software sends a WebSocket Ping request to Mews every 5 minutes to monitor the connection. If the Ping request fails, the interface ia restarted automatically, and the synchronization process is triggered when successfully connected again.

 

Is the Ping/Pong solution implemented through Mews' API? 

 

The Ping/Pong solution is not implemented through Mews' API. It is a solution that should be handled by the partner.

 

Where can I find more information about the Ping/Pong solution?

 

You can find further information on the Ping/Pong solution in the following here.  Here you can check how to send a Ping/Pong request for WebSocket in Javascript.

 
Was this article helpful?
00



Feedback