# TCG FE WebSocket Notification [TOC] ## Instructions 1. Get websocket URL from API (/lgw/im/url) 2. Connect websocket 3. Subcribe topics ### Step 1: Get websocket URL from API **Description** - Get Websocket URL - This API like RSA API, sometimes will be changed. **Path** - ` /lgw/im/url` **Http Header** |Parameter Name|Required|Type|Description | |:---- |:---|:----- |----- | | Merchant | Y | String | usport | **HTTP Method** - GET **Parameters** **Response Example** ``` json { "merchantCode":"test", "imUrl":"https://test-socket.uxgaming.com" } ``` ### Step 2: Connect websocket Please reference [sockjs-client](https://github.com/sockjs/sockjs-client "sockjs-client") **Example code** ```javascript // url from Step 1, append /rtmsg var url = step1Url + "/rtmsg"; var sockjs = new SockJS(url, _reserved, options); ``` ### Step 3: Subcribe topics Please reference [stompjs](https://stomp-js.github.io/stomp-websocket/codo/extra/docs-src/Usage.md.html) **Subscribe user channel with customer id** - Topic: /topic/user/${customerId} - See [Available Topics](#Available-Topics-and-Response-Example) **Example code** - login, passcode all put TCG token - subscribe /topic/user/ + customerId ```javascript var url = step1Url + "/rtmsg"; var sockjs = new SockJS(url, _reserved, options); var client = Stomp.over(sockjs); // login, passcode all put TCG token client.connect(login, passcode, connectCallback); var subscription = client.subscribe("/topic/user/" + customerId, (payload) => { const body = JSON.parse(payload.body); // do something const { type } = body; }); ``` ## Available Topics and Response Example ### Manual Promotion **(type === MANUAL_PROMO)** When players received manual promotions. :::warning :warning: Suggest you refresh balance. ::: ```json { "type": "MANUAL_PROMO", "title": "【彩金】", "message": "", "data": { "promotionClaimId": "891970" }, "popup": false, } ``` ### Inbox Mail (**type === INBOX**) When players received INBOX mail. :::warning :warning: Suggest you refresh unread inbox count. ::: ```json { "type": "INBOX", "title": "mail title", "message": "mail content", "popup": true, } ``` ### Promotion Claimed (**type === PROMOTION_CLAIM**) When players received auto claim promotions. :::warning :warning: Suggest you refresh balance. ::: ```json { "type": "PROMOTION_CLAIM", "title": "promotion title", "message": "promotion content", "popup": true, } ``` ### Online message (**type === ONLINE_MSG**) Send from backend/subsystems. ```json { "type": "ONLINE_MSG", "title": "hello", "message": "you're lucky one", "popup": true, } ``` ### Deposit requests (**type === DEPOSIT**) <font color="#f00">Must use this instead of old one. Old push can not use anymore soon.</font> :::success :bulb: $.data has detail request info, can be use for FE message. (amount, time, success) ::: :::warning :warning: Suggest you refresh balance. ::: **Deposit request success 充值成功** ```json { "type": "DEPOSIT", "title": "DEPOSIT", "message": "", "data": { "amount": 20, "time": 1593486445000, "success": true }, "popup": true, } ``` **Deposit request failed or rejected 充值失敗/拒絕** ```json { "type": "DEPOSIT", "title": "DEPOSIT", "message": "", "data": { "amount": 12, "time": 1593486553000, "success": false }, "popup": true, } ``` ### Withdraw requests (**type === WITHDRAW**) <font color="#f00">Must use this instead of old one. Old push can not use anymore soon.</font> :::success :bulb: $.data has detail request info, can be use for FE message. (amount, time, success) ::: :::warning :warning: Suggest you refresh balance. ::: **Withdraw request success 提現成功** ```json { "type": "WITHDRAW", "title": "WITHDRAW", "message": "", "data": { "amount": 11.4, "time": 1593605442000, "success": true } } ``` **Withdraw request failed or rejected 提現失敗/拒絕** ```json { "type": "WITHDRAW", "title": "WITHDRAW", "message": "", "data": { "amount": 12, "time": 1593605317000, "success": false } } ```