WebSocket Real-time Road Interface Documentation

Connection URL

To connect to the WebSocket service, use the following URL:

ws://apiurl/ws8881

Connection Example

Here is an example of connecting to the WebSocket service using JavaScript:

const socket = new WebSocket('ws://apiurl/ws8881');

socket.onopen = function(event) {
    console.log('Connected to WebSocket server.');
    // Send message command 1 after successful connection
    const apiKey = "yourApiKey";
    const agent = "agentName";
    const timestamp = Date.now();
    const sign = md5(agent + apiKey + timestamp);
    const message = {
        cmd: "connect",
        agent: agent,
        sign: sign,
        time: timestamp,
        tableIds: [10101, 10102, 10103]
    };
    socket.send(JSON.stringify(message));
};

socket.onmessage = function(event) {
    console.log('Message from server:', event.data);
};

socket.onclose = function(event) {
    console.log('Disconnected from WebSocket server.');
};

socket.onerror = function(error) {
    console.error('WebSocket error:', error);
};

// MD5 hash function
function md5(string) {
    // Implementation of MD5 hash function
    // You can use a library like CryptoJS for this
    return CryptoJS.MD5(string).toString();
}

Message Types

1. Connect

Sent by the client to establish a connection.

Signature rule: Use the MD5 algorithm to hash the concatenated string of `agent` name, `apiKey`, and `timestamp`.

{
    "cmd": "connect",
    "agent": "agentName",
    "sign": "MD5(agentName + apiKey + timestamp)",
    "time": "timestamp",
    "tableIds": [10101, 10102, 10103]
}

Connection Response Data Structure

The following is the data structure returned by the connect command:

{
    "codeId": 0, // Code ID
    "cmd": "connect", // Command type
    "agent": "DG01010100", // Agent name
    "sign": "368c0add887c525cdf16cf9bdf897779", // Signature
    "tableIds": [10101, 10102, 10103], // List of table IDs
    "tableNameMap": { // Table ID to table name
        "10101": "D01",
        "10102": "D02",
        "10103": "D03"
    },
    "tableGoodRoadType": { // Table ID to good road type and count (used for long dragon or single jump)
        "10101": "1-6", // 6 long banker
        "10102": "3-5", // 5 single hop banker road
        "10103": "12-0" // rows and rows
    },
    "tableOnlineCount": { // Table ID to number of online users
        "10101": 1023,
        "10102": 249,
        "10103": 441
    },
    "tablePicture": { // Table ID to table screenshot path
        "10101": "241220/10101/i1oQ.jpg",
        "10102": "241220/10102/Xkot.jpg",
        "10103": "241220/10103/5YJu.jpg"
    },
    "tableRoads": { // Table ID to list of road data
        "10101": ["#5#0#8", "#1#0#9", "#1#0#7", "#5#0#8", "#1#0#8", "#5#0#7", "#3#0#7", "#6#0#8", "#6#0#5", "#5#0#9", "#1#0#9", "#5#0#9", "#3#0#9", "#1#0#7", "#5#0#7", "#1#0#8", "#1#0#8", "#5#0#7", "#5#0#7", "#5#0#8", "#5#0#8", "#5#0#7", "#1#0#8", "#11#0#0", "#9#0#9", "#9#0#9", "#9#0#6", "#2#1#6", "#5#0#9", "#1#0#9", "#1#0#9", "#5#0#8", "#5#0#8", "#1#0#7", "#5#0#2", "#5#0#1", "#1#0#7", "#5#0#9", "#1#1#6", "#1#0#7", "#1#0#1", "#1#0#7", "#5#0#9"],
        "10102": ["#1#0#8", "#1#0#8", "#3#0#8", "#5#0#7", "#5#0#7", "#1#0#5"],
        "10103": ["#9#0#4", "#5#0#9", "#5#0#6", "#1#0#3", "#5#0#7", "#1#0#3", "#1#0#8", "#5#0#8", "#1#0#4", "#9#0#7", "#5#0#7", "#1#0#4", "#5#0#8", "#6#0#7", "#5#0#9", "#5#0#8", "#9#0#6", "#1#1#6"]
    }
}

2. Heartbeat

Sent by the client to keep the connection alive.

{
    "cmd": "ping"
}

3. Push Roads

Sent by the server to push road data.

{
    "cmd": "push_roads",
    "tableId": 123,
    "roads": ["road1", "road2"],
    "online": 100,
    "goodRoad": "type-count"
}

4. Push Change Picture

Sent by the server to push live dealer change picture data.

{
    "cmd": "push_change_picture",
    "tableId": 123,
    "picture": "dealerPhotoUrl"
}

5. Road Parsing Rules

Game Example Definition
Classic, Speed, Live, Sexy Baccarat (GameId=1)
Insurance Baccarat (GameId=2)
Competitive Baccarat (GameId=8)
road1="#6#0#3"
Separated by #: 
road[1] Range [1-12]
1: Banker wins, 2: Banker wins with Banker pair, 3: Banker wins with Player pair, 4: Banker wins with Banker and Player pair
5: Player wins, 6: Player wins with Banker pair, 7: Player wins with Player pair, 8: Player wins with Banker and Player pair
9: Tie wins, 10: Tie wins with Banker pair, 11: Tie wins with Player pair, 12: Tie wins with Banker and Player pair
road[2]: Banker 6 points, 1: Yes, 0: No
road[3]: Winning side points [0-9]
Dragon Tiger (GameId=3)
road1="#2#0101"
Separated by #: 
road[1] Range [1-3]
1: Dragon wins, 2: Tiger wins, 3: Tie wins
road[2][0] 0: Dragon Odd, 1: Dragon Even
road[2][1] 0: Dragon Red, 1: Dragon Black
road[2][2] 0: Tiger Odd, 1: Tiger Even
road[2][3] 0: Tiger Red, 1: Tiger Black
Roulette (GameId=4)
road1="#16"
Separated by #: 
[0-36] The number on which the ball landed
Sic Bo (GameId=5)
road1="#123"
Separated by #: 
[1-6] The points of each dice
Fan Tan (GameId=6)
road1="#1"
Separated by #: 
[1-4] Remaining beans
Niu Niu (GameId=7)
road1="#0,1,0,5#1,1,1#27"
Separated by #: 
road[1][0] Banker points
road[1][1] Player 1 points
road[1][2] Player 2 points
road[1][3] Player 3 points
road[2][0] Player 1 win/loss, 1: Win, 0: Loss
road[2][1] Player 2 win/loss, 1: Win, 0: Loss
road[2][3] Player 3 win/loss, 1: Win, 0: Loss
road[3] First card
Golden Flower (GameId=11)
road1="#2#1,1,7,14,1#"
Separated by #: 
road[1][0] 1: Black wins, 2: Red wins, 3: Draw
road[2][0] Black hand type
road[2][1] Red hand type
road[2][2] Black highest card, range [2-14], representing 2-A
road[2][3] Red highest card, range [2-14], representing 2-A
road[2][4] Bonus hand type: 0: Draw, 1: High card, 2: Pair (9-A), 3: Straight, 4: Flush, 5: Straight flush, 6: Three of a kind, 7: Three of a kind killer
Color Disc (GameId=14)
road1="#2"
Separated by #: 
road[0] Range [0-4]
0: 4 white
1: 3 white 1 red
2: 2 white 2 red
3: 3 red 1 white
4: 4 red
Odd: 3 red, 1 white button or 3 white, 1 red button
Even: 4 red buttons, 4 white buttons or 2 white, 2 red buttons
San Gong (GameId=16)
road1="#2P7,6,1P3,0,1,3,0,1#1,1,1#1"
Separated by #: 
road[1] [0]-[3]: Banker, Player 1, Player 2, Player 3 results, e.g., 8 represents 8 points, 1P1 represents single gong, 3P0 represents three gongs
road[2] [4]-[7]: Banker, Player 1, Player 2, Player 3 hand types above pairs 0: None, 1: Pair, 2: Flush, 3: Straight, 4: Leopard, 5: Straight flush
road[3] [8]-[10]: Player 1, Player 2, Player 3 compared to Banker, 1 Banker wins, 2 Player wins, 3 Draw
road[4]: First card
Andar Bahar (GameId=20)
road1="#1#31#48#"
Separated by #: 
road[1] Range [1-2]
1: Andar
2: Bahar
road[2]: Number of cards dealt
road[3]: Joker card

6. Good Road Types

Type Description
1 Long Banker
2 Long Player
3 Single Hop Banker Road
4 One Banker Two Player
5 One Player Two Banker
8 Meet Banker Jump
9 Meet Player Jump
10 Meet Banker Row
11 Meet Player Row
12 Rows and Rows