Ping
Ping the connection to check connectivity. This endpoint can also be used to reset the idle connection timeout and avoid connection being dropped by the server. See Heartbeats for more details.
Path
ping
Response Body
ts
Current server time.
Example:
2024-05-01T10:30:00.000ZResponse codes
| Code | Meaning | Description |
|---|---|---|
| 200 | OK | The request has succeeded. The client can read the result in the body if present. |
Request example
ping
// Connect to the server
const ws = new WebSocket('wss://api.emogg.com/ws/v1');
// Helper function for sending messages
const sendMessage = (path, body, id) => {
const payload = {
"id": id,
"path": path,
"body": body
}
console.log('// Request\n', payload)
ws.send(JSON.stringify(payload));
}
// Authenticate connection
ws.onopen = () => sendMessage("auth:token", { "token": "YOUR_TOKEN" }, 1);
// Server messages callback
ws.onmessage = function (payload) {
const message = JSON.parse(payload.data)
console.log('// Response\n', message)
const { id, path, status, body } = message
if (path === 'auth:token' && status === 200) { // If successfully authenticated, send our message
const message = {}
sendMessage("ping", message)
}
};
Result
// Request
{ "id": 1, "path": "auth:token", "body": { "token": "YOUR_TOKEN" } }
// Response
{ "id": 1, "path": "auth:token", "status": 200 }
// Request
{ "path": "ping" }
// Response
{ "id": null, "path": "ping", "status": 200, "body": {"ts":"2024-05-01T10:30:00.000Z"} }
// More requests and responses
{...}