WebSocket
Endpoint
wss://api.white.market/ws_endpoint
Пример подключения
JavaScript
Используйте https://github.com/centrifugal/centrifuge-js.
const centrifuge = new Centrifuge(wsEndpoint, {
debug: true,
token: token
});
centrifuge.on('connecting', function (ctx) {
addResponse('Init', `connecting: ${ctx.code}, ${ctx.reason}`)
}).on('connected', function (ctx) {
addResponse('Init', `connected over ${ctx.transport}`)
}).on('disconnected', function (ctx) {
addResponse('Init', `disconnected: ${ctx.code}, ${ctx.reason}`)
}).on('publication', function(ctx) {
addResponse('Event', JSON.stringify(ctx));
});
// Subscribe products updates
const marketProductsUpdates = centrifuge.newSubscription('market_products_updates');
marketProductsUpdates.on('publication', function(ctx) {
addResponse('Event', JSON.stringify(ctx));
});
marketProductsUpdates.subscribe();
centrifuge.connect();
Golang
Используйте https://github.com/centrifugal/centrifuge-go.
Пример использования библиотеки https://github.com/centrifugal/centrifuge-go/blob/master/examples/token_subscription/main.go
Dart
Используйте https://github.com/centrifugal/centrifuge-dart.
Swift
Используйте https://github.com/centrifugal/centrifuge-swift.
Java
Используйте https://github.com/centrifugal/centrifuge-java.
Пример использования библиотеки https://github.com/centrifugal/centrifuge-java/blob/master/example/src/main/java/io/github/centrifugal/centrifuge/example/Main.java
Python
Используйте https://github.com/centrifugal/centrifuge-python.
Пример использования библиотеки https://github.com/centrifugal/centrifuge-python/blob/master/example.py
Другое
Подключитесь к endpoint и отправьте:
{"connect":{"token":"JWT_TOKEN","name":"js"},"id":1}
{"subscribe":{"channel":"market_products_updates"},"id":2}
Вы получите сообщения, подобные приведённым ниже:
{"push":{"channel":"market_products_updates","pub":{"data":{"message":{"type":"market_product_edited","content":{"id":"1ef8d741-8ae1-6af4-b225-000000000002","price":"2.10"}}}}}}
WARNING: Вы можете получить несколько сообщений в одном ответе, разделённых \n
{"push":{"channel":"market_products_updates","pub":{"data":{"message":{"type":"market_product_edited","content":{"id":"1ef8d741-8ae1-6af4-b225-000000000002","price":"2.10"}}"}}}}
{"push":{"channel":"market_products_updates","pub":{"data":{"message":{"type":"market_product_edited","content":{"id":"1ef8d741-8ae1-6af4-b225-000000000003","price":"3.10"}}"}}}}
{"push":{"channel":"market_products_updates","pub":{"data":{"message":{"type":"market_product_edited","content":{"id":"1ef8d741-8ae1-6af4-b225-000000000004","price":"4.10"}}"}}}}
Общий формат
{
"channel":"CHANNEL_NAME",
"pub":{
"data":{
"message":"ENCODED_AND_ESCAPED_JSON_CONTENT"
}
}
}
При получении данных нужно снять экранирование и декодировать json, чтобы получить данные
Пример
{
"channel":"market_products_updates",
"pub":{
"data":{
"message":"{\"type\":\"market_product_added\",\"content\":{\"id\":\"1ef6c2b5-7f94-67c0-8e23-000000000001\",\"app_id\":\"730\",\"asset_id\":\"36857146063\",\"class_id\":\"469440539\",\"instance_id\":\"302028390\",\"price\":\"0.020\",\"name_hash\":\"G3SG1 | Green Apple (Minimal Wear)\",\"inspect_url\":\"steam:\\\/\\\/rungame\\\/730\\\/76561202255233023\\\/+csgo_econ_action_preview%20S76561198000000000A10000000000D10000000000000000000\",\"delivery_type\":\"semi\"}}"
}
}
}