The SDKs handle connections to Leap for you. This documentation is written for
transparency & for developers wanting to create their own SDKs for Hop.
Leap Edge Socket
The LE (Leap Edge) socket allows clients & SDKs to connect to the following Hop realtime services:- Pipe
- Channels
Protocol
LE 1.0 currently only supports connections via WebSocket, which is accessible globally viawss://leap.hop.io/ws. The IP address behind the hostname is
announced by the Hop anycast network, so you should be connected to the closest
PoP.
Messages with LE are exchanged through a series of opcodes, documented below.
All messages sent from LE are formatted with the following payload type:
Encoding & Compression
When connecting to the websocket, LE supports 2 query parameters:encoding and
compression. Refer to the below table for possible values.
Note: The
json encoding type will just send plaintext minified JSON
objects.
Opcode Map
rx = receive (from LE, to client)
tx = transmit (from client, to LE)
Connection flow
Connecting
We recommend you explicitly pass in an encoding type with the LE socket URL, e.g.wss://leap.hop.io/1.0/ws?encoding=json.
Once connected, you should receive an Op 1: Hello
payload, which contains setup information about the LE session for the client to
use, which includes the heartbeat interval:
Example Op 1: Hello
4002: Identify timeout error.
Heartbeating
Once receiving Op: 1 Hello, the LE client or SDK should immediately start a repeating interval which sends Op 3: Heartbeat on the interval. Please note that Leap Edge calculates the time drift over time,so if you drift too far out of the expected heartbeat interval then you may be disconnected from the socket with error4007: Out of sync.
Leap Edge may also send Op 3 down to the client with a tag in the data field.
If the client receives this, it needs to immediately respond with Op 3:
Heartbeat with the same tag in the data field.