### WebSocket Client Connection Example Source: https://context7.com/wushuaihua520/barragegrab/llms.txt Example of how a client can connect to the local WebSocket server to receive real-time danmaku data using JavaScript. ```APIDOC ## WebSocket Client Connection Example ### Description Demonstrates how to connect to the local WebSocket server (`ws://127.0.0.1:8888`) using JavaScript to receive and process real-time danmaku and other live stream events. ### Usage Example (JavaScript) ```javascript const ws = new WebSocket('ws://127.0.0.1:8888'); ws.onopen = function() { console.log('Connected to the danmaku server'); }; ws.onmessage = function(event) { const message = JSON.parse(event.data); switch(message.Type) { case 1: // Member entry console.log(`[Enter] ${message.Data.User.NickName} joined`); break; case 2: // Follow console.log(`[Follow] ${message.Data.User.NickName} followed the streamer`); break; case 3: // Danmaku console.log(`[Danmaku] ${message.Data.User.NickName}: ${message.Data.Content}`); break; case 4: // Like console.log(`[Like] ${message.Data.User.NickName} liked ${message.Data.Count} times`); break; case 5: // Gift console.log(`[Gift] ${message.Data.User.NickName} sent ${message.Data.GiftName} x ${message.Data.RepeatCount}`); break; case 7: // Stats console.log(`[Stats] Online: ${message.Data.OnlineUserCountStr}, Total: ${message.Data.TotalUserCountStr}`); break; case 8: // Live status console.log(`[System] ${message.Data.Content}`); break; } }; ws.onerror = function(error) { console.error('WebSocket error:', error); }; ws.onclose = function() { console.log('Connection closed'); }; ``` ``` -------------------------------- ### IBarrageGrabService Interface Source: https://context7.com/wushuaihua520/barragegrab/llms.txt The core interface for implementing barrage grabbing services for different live streaming platforms. It provides methods to start, stop, and restart the grabbing process, along with events for connection status. ```APIDOC ## IBarrageGrabService Interface ### Description Defines the contract for barrage grabbing services. Allows starting, stopping, and restarting the service, and provides event notifications for connection status changes (Open, Message, Error, Close). ### Methods - **Start(string liveId)**: Starts the barrage grabbing service for a given live stream ID. - **Stop()**: Stops the barrage grabbing service. - **ReStart()**: Restarts the barrage grabbing service. ### Events - **OnOpen**: Triggered when the WebSocket connection is opened. - **OnMessage**: Triggered when a message is received. - **OnError**: Triggered when an error occurs. - **OnClose**: Triggered when the connection is closed. ### Usage Example (C#) ```csharp var douyinService = new DouyinBarrageGrabService(); douyinService.OnOpen += (sender, e) => { Console.WriteLine("WebSocket connection established"); }; douyinService.OnError += (sender, e) => { Console.WriteLine("An error occurred, attempting to reconnect..."); douyinService.ReStart(); }; // Start grabbing (provide the live stream ID) douyinService.Start("751990192217"); // Stop grabbing douyinService.Stop(); ``` ``` -------------------------------- ### Global Configuration Settings Source: https://context7.com/wushuaihua520/barragegrab/llms.txt Defines essential global configuration parameters for the application, including WebSocket server addresses and API endpoints. ```csharp public static class GlobalConfigs { // 本地WebSocket服务器地址(客户端连接此地址接收弹幕) public static string LocalWebSocketServer_Location = "ws://0.0.0.0:8888"; // 抖音直播间URL前缀 public static string LiveUrl_Douyin = "https://live.douyin.com"; // 当前版本号 public static string Version = "v1.9.1"; // 签名API服务地址(用于获取WSS签名) public static string SignApi_Domain = "https://api.aiobs.cn"; public static string SignApi_Url = "/Douyin/Douyin/SignWss"; // API Key(测试用,生产环境需申请独立Key) public static string SignApi_Key = "test-apikey-xxx"; } ``` -------------------------------- ### 管理 LocalWebSocketServer 本地服务器 Source: https://context7.com/wushuaihua520/barragegrab/llms.txt 展示了如何初始化本地 WebSocket 服务器、广播 JSON 消息以及释放资源。 ```csharp // 服务器初始化和启动 var wsServer = new LocalWebSocketServer(); wsServer.Start(); // 广播消息给所有已连接的客户端 await wsServer.Broadcast("{\"Type\":3,\"Data\":{\"Content\":\"Hello World\"}}"); // 重启服务器 wsServer.ReStart(); // 释放资源 wsServer.Dispose(); ``` -------------------------------- ### 实现 IBarrageGrabService 接口与使用 Source: https://context7.com/wushuaihua520/barragegrab/llms.txt 定义了弹幕抓取服务的核心接口,并展示了如何实例化服务、注册事件处理程序以及控制抓取生命周期。 ```csharp // 接口定义 public interface IBarrageGrabService { // 启动弹幕抓取服务 // liveId: 直播间ID,如抖音直播间URL https://live.douyin.com/751990192217 中的 751990192217 void Start(string liveId); // 停止弹幕抓取服务 void Stop(); // 重启弹幕抓取服务 void ReStart(); // WebSocket连接打开时触发 event EventHandler? OnOpen; // 收到消息时触发 event EventHandler? OnMessage; // 发生错误时触发 event EventHandler? OnError; // 连接关闭时触发 event EventHandler? OnClose; } // 使用示例 var douyinService = new DouyinBarrageGrabService(); // 注册事件处理 douyinService.OnOpen += (sender, e) => { Console.WriteLine("WebSocket连接已建立"); }; douyinService.OnError += (sender, e) => { Console.WriteLine("发生错误,尝试重连..."); douyinService.ReStart(); }; // 启动抓取(传入直播间ID) douyinService.Start("751990192217"); // 停止抓取 douyinService.Stop(); ``` -------------------------------- ### GlobalConfigs Source: https://context7.com/wushuaihua520/barragegrab/llms.txt System global configuration items, including WebSocket server address, API interface address, and other core parameters. ```APIDOC ## GlobalConfigs ### Description System global configuration items, including WebSocket service address, API interface address, and other core parameters. ### Configuration Details - **LocalWebSocketServer_Location** (string): Local WebSocket server address (client connects to this address to receive barrage). - Example: `"ws://0.0.0.0:8888"` - **LiveUrl_Douyin** (string): Douyin live room URL prefix. - Example: `"https://live.douyin.com"` - **Version** (string): Current version number. - Example: `"v1.9.1"` - **SignApi_Domain** (string): Signature API service domain (used to obtain WSS signature). - Example: `"https://api.aiobs.cn"` - **SignApi_Url** (string): Signature API endpoint URL. - Example: `"/Douyin/Douyin/SignWss"` - **SignApi_Key** (string): API Key (for testing, apply for an independent Key in production environment). - Example: `"test-apikey-xxx"` ``` -------------------------------- ### Enter Room Message (Type=1) Source: https://context7.com/wushuaihua520/barragegrab/llms.txt Represents a user entering a live room. Includes user information and current room occupancy. ```json { "Type": 1, "Data": { "MemberCount": 6438, "MsgId": 7338701468109681418, "User": { "FollowingCount": 269, "Id": 101685213389, "ShortId": 1196943920, "DisplayId": "1196943920", "NickName": "小铭.", "Level": 0, "PayLevel": 0, "Gender": 1, "Avatar": "https://p26.douyinpic.com/aweme/100x100/xxx.jpeg", "SecUid": "MS4wLjABAAAA...", "FansClub": { "ClubName": "", "Level": 0 }, "FollowerCount": 23, "FollowStatus": 1 }, "Content": "小铭. 来了", "RoomId": 7338688640757009202 } } ``` -------------------------------- ### 连接 WebSocket 客户端接收数据 Source: https://context7.com/wushuaihua520/barragegrab/llms.txt 通过 JavaScript WebSocket 客户端连接本地服务,并根据消息类型处理不同的直播间事件。 ```javascript // JavaScript WebSocket客户端连接示例 const ws = new WebSocket('ws://127.0.0.1:8888'); ws.onopen = function() { console.log('已连接到弹幕服务器'); }; ws.onmessage = function(event) { const message = JSON.parse(event.data); switch(message.Type) { case 1: // 进入房间 console.log(`[进入] ${message.Data.User.NickName} 来了`); break; case 2: // 关注 console.log(`[关注] ${message.Data.User.NickName} 关注了主播`); break; case 3: // 弹幕 console.log(`[弹幕] ${message.Data.User.NickName}: ${message.Data.Content}`); break; case 4: // 点赞 console.log(`[点赞] ${message.Data.User.NickName} 点了 ${message.Data.Count} 个赞`); break; case 5: // 礼物 console.log(`[礼物] ${message.Data.User.NickName} 送出 ${message.Data.GiftName} x ${message.Data.RepeatCount}`); break; case 7: // 统计 console.log(`[统计] 在线: ${message.Data.OnlineUserCountStr}, 累计: ${message.Data.TotalUserCountStr}`); break; case 8: // 直播状态 console.log(`[系统] ${message.Data.Content}`); break; } }; ws.onerror = function(error) { console.error('WebSocket错误:', error); }; ws.onclose = function() { console.log('连接已断开'); }; ``` -------------------------------- ### Douyin Follow Message Format Source: https://github.com/wushuaihua520/barragegrab/blob/master/README.md This JSON object represents a user following the live stream host. It includes the follower's details and a confirmation message. ```json { "Type": 2, "Data": { "MsgId": 7338701469288500020, "User": { "FollowingCount": 217, "Id": 70182119246, "ShortId": 4125395366, "DisplayId": "dyi9z7nn8swe", "NickName": "♥", "Level": 0, "PayLevel": 0, "Gender": 0, "Birthday": 0, "Telephone": null, "Avatar": "https://p11.douyinpic.com/aweme/100x100/aweme-avatar/tos-cn-i-0813_892bdf2e00db4753991ecb8348ef25c5.jpeg?from=3067671334", "SecUid": "MS4wLjABAAAA3XBoQKvXh1VIONd6G4edMhwXt2o_bsJQsL-j1g4nN5E", "FansClub": { "ClubName": "", "Level": 0 }, "FollowerCount": 9, "FollowStatus": 1 }, "Content": "♥ 关注了主播", "RoomId": 7338688640757009202 } } ``` -------------------------------- ### User Entry Message (Type=1) Source: https://context7.com/wushuaihua520/barragegrab/llms.txt Details of the message pushed when a user enters a live room. Includes user information and current room member count. ```APIDOC ## User Entry Message (Type=1) ### Description User enters a live room message, including user information and current room member count. ### Message Type 1 ### Data Structure ```json { "Type": 1, "Data": { "MemberCount": "integer", "MsgId": "long", "User": { "FollowingCount": "integer", "Id": "long", "ShortId": "integer", "DisplayId": "string", "NickName": "string", "Level": "integer", "PayLevel": "integer", "Gender": "integer", "Avatar": "string", "SecUid": "string", "FansClub": { "ClubName": "string", "Level": "integer" }, "FollowerCount": "integer", "FollowStatus": "integer" }, "Content": "string", "RoomId": "long" } } ``` ``` -------------------------------- ### Douyin Enter Room Message Format Source: https://github.com/wushuaihua520/barragegrab/blob/master/README.md This JSON structure represents a user entering a Douyin live stream room. It includes user details, room information, and a message indicating entry. ```json { "Type": 1, "Data": { "MemberCount": 6438, "MsgId": 7338701468109681418, "User": { "FollowingCount": 269, "Id": 101685213389, "ShortId": 1196943920, "DisplayId": "1196943920", "NickName": "小铭. ", "Level": 0, "PayLevel": 0, "Gender": 1, "Birthday": 0, "Telephone": null, "Avatar": "https://p26.douyinpic.com/aweme/100x100/aweme-avatar/tos-cn-i-0813c001_oIxcMIzDAm9MAQkIKCelAmCngoCeAA5ZbkTAaI.jpeg?from=3067671334", "SecUid": "MS4wLjABAAAA0MIs0Ia9g0qJgNLjbb6Ui21F7-kN6linqTJ0SlrxbpE", "FansClub": { "ClubName": "", "Level": 0 }, "FollowerCount": 23, "FollowStatus": 1 }, "Content": "小铭. 来了", "RoomId": 7338688640757009202 } } ``` -------------------------------- ### Connect to BarrageGrab via Python WebSocket Source: https://context7.com/wushuaihua520/barragegrab/llms.txt Connects to the local WebSocket server to process real-time barrage, gift, and user entry events. Requires the 'websocket-client' library. ```python import websocket import json def on_message(ws, message): data = json.loads(message) msg_type = data.get('Type') if msg_type == 1: # 进入房间 user = data['Data']['User'] print(f"[进入] {user['NickName']} 来了") elif msg_type == 3: # 弹幕 user = data['Data']['User'] content = data['Data']['Content'] print(f"[弹幕] {user['NickName']}: {content}") elif msg_type == 5: # 礼物 user = data['Data']['User'] gift = data['Data']['GiftName'] count = data['Data']['RepeatCount'] print(f"[礼物] {user['NickName']} 送出 {gift} x {count}") def on_error(ws, error): print(f"错误: {error}") def on_close(ws, close_status_code, close_msg): print("连接关闭") def on_open(ws): print("已连接到弹幕服务器") if __name__ == "__main__": ws = websocket.WebSocketApp( "ws://127.0.0.1:8888", on_open=on_open, on_message=on_message, on_error=on_error, on_close=on_close ) ws.run_forever() ``` -------------------------------- ### 使用 OpenBarrageMessage 实体 Source: https://context7.com/wushuaihua520/barragegrab/llms.txt 展示了统一弹幕消息包装类的定义,以及如何创建消息实例并序列化广播。 ```csharp public class OpenBarrageMessage { public MessageTypeEnum Type { get; set; } // 消息类型 public object? Data { get; set; } // 消息数据 } // 创建弹幕消息示例 var chatMessage = new OpenBarrageMessage { Type = MessageTypeEnum.Chat, Data = new DouyinMsgChat { MsgId = 7338697347818230818, Content = "主播好厉害!", RoomId = 7338657973104921378, User = new DouyinUser { Id = 1411400097607259, NickName = "小明", Avatar = "https://p3.douyinpic.com/aweme/100x100/xxx.jpeg" } } }; // 序列化为JSON并广播 string json = JsonConvert.SerializeObject(chatMessage); await wsServer.Broadcast(json); ``` -------------------------------- ### LocalWebSocketServer Source: https://context7.com/wushuaihua520/barragegrab/llms.txt A local WebSocket server that broadcasts captured danmaku data to connected clients. It listens on a specified address and port, supporting multiple simultaneous connections. ```APIDOC ## LocalWebSocketServer ### Description Provides a local WebSocket server to broadcast captured danmaku data to client applications in real-time. It defaults to listening on `ws://0.0.0.0:8888` and manages multiple client connections. ### Methods - **Start()**: Initializes and starts the WebSocket server. - **Broadcast(string message)**: Broadcasts a message to all connected clients. - **ReStart()**: Restarts the WebSocket server. - **Dispose()**: Releases resources used by the server. ### Usage Example (C#) ```csharp // Initialize and start the server var wsServer = new LocalWebSocketServer(); wsServer.Start(); // Broadcast a message to all connected clients await wsServer.Broadcast("{\"Type\":3,\"Data\":{\"Content\":\"Hello World\"}}"); // Restart the server wsServer.ReStart(); // Release resources wsServer.Dispose(); ``` ``` -------------------------------- ### Define DouyinUser Data Model in C# Source: https://context7.com/wushuaihua520/barragegrab/llms.txt Represents the user data structure received from the service. Includes a helper snippet for scaling avatar image URLs. ```csharp public class DouyinUser { public long Id { get; set; } // 用户真实ID public long ShortId { get; set; } // 短ID public string? DisplayId { get; set; } // 自定义抖音号 public string? NickName { get; set; } // 昵称 public int Level { get; set; } // 等级 public int PayLevel { get; set; } // 支付等级(土豪等级) public int Gender { get; set; } // 性别:1男 2女 public string? Avatar { get; set; } // 头像URL public string? SecUid { get; set; } // 用户主页ID public long FollowerCount { get; set; } // 粉丝数 public long FollowingCount { get; set; } // 关注数 public long FollowStatus { get; set; } // 对主播关注状态:0未关注 1已关注 public DouyinFansClub? FansClub { get; set; } // 粉丝团信息 } // 获取更大尺寸的头像 string avatarUrl = user.Avatar; // 原始100x100 string largeAvatar = avatarUrl.Replace("100x100", "200x200"); // 替换为200x200 ``` -------------------------------- ### Douyin Like Message Format Source: https://github.com/wushuaihua520/barragegrab/blob/master/README.md This JSON object signifies a user liking the live stream. It includes the number of likes, total likes, sender details, and room information. ```json { "Type": 4, "Data": { "Count": 5, "Total": 418060, "MsgId": 7338697335486453772, "User": { "FollowingCount": 2885, "Id": 101385281892, "ShortId": 1173935310, "DisplayId": "1173935310", "NickName": "种花的不买张刀(杨清)", "Level": 0, "PayLevel": 19, "Gender": 0, "Birthday": 0, "Telephone": null, "Avatar": "https://p3.douyinpic.com/aweme/100x100/aweme-avatar/mosaic-legacy_1c9f300069de5b1a41303.jpeg?from=3067671334", "SecUid": "MS4wLjABAAAA2QEhMnB1rX4ePA7iQ9SQ1805lEcxeBQOQ5SBAysazAU", "FansClub": { "ClubName": "熊家人", "Level": 13 }, "FollowerCount": 277, "FollowStatus": 1 }, "Content": "种花的不买张刀(杨清) 为主播点了5个赞,总点赞418060", "RoomId": 7338657973104921378 } } ``` -------------------------------- ### Douyin Statistics Message Format Source: https://github.com/wushuaihua520/barragegrab/blob/master/README.md This JSON object provides live stream statistics, including current and total online user counts. It is sent periodically or upon request. ```json { "Type": 7, "Data": { "OnlineUserCount": 3937, "TotalUserCount": 269277, "TotalUserCountStr": "26.9万", "OnlineUserCountStr": "3937", "MsgId": 7338699901570204223, "User": null, "Content": "当前直播间人数 3937,累计直播间人数 26.9万", "RoomId": 7338657973104921378 } } ``` -------------------------------- ### Room Statistics Message (Type=7) Source: https://context7.com/wushuaihua520/barragegrab/llms.txt Periodically pushed room statistics, including real-time online users and cumulative viewers. ```APIDOC ## Room Statistics Message (Type=7) ### Description Periodically pushed room statistics, including real-time online users and cumulative viewers. ### Message Type 7 ### Data Structure ```json { "Type": 7, "Data": { "OnlineUserCount": "integer", "TotalUserCount": "integer", "TotalUserCountStr": "string", "OnlineUserCountStr": "string", "MsgId": "long", "User": "object | null", "Content": "string", "RoomId": "long" } } ``` ``` -------------------------------- ### Like Message (Type=4) Source: https://context7.com/wushuaihua520/barragegrab/llms.txt Represents a user liking the stream. Includes the number of likes in this action and the total cumulative likes. ```json { "Type": 4, "Data": { "Count": 5, "Total": 418060, "MsgId": 7338697335486453772, "User": { "Id": 101385281892, "NickName": "热心观众", "PayLevel": 19, "FansClub": { "ClubName": "熊家人", "Level": 13 } }, "Content": "热心观众 为主播点了5个赞,总点赞418060", "RoomId": 7338657973104921378 } } ``` -------------------------------- ### Live Status Change Message (Type=8) Source: https://context7.com/wushuaihua520/barragegrab/llms.txt Pushed when the live room status changes, such as the end of the broadcast. ```APIDOC ## Live Status Change Message (Type=8) ### Description Live room status change message, such as live end. ### Message Type 8 ### Data Structure ```json { "Type": 8, "Data": { "MsgId": "long", "User": "object | null", "Content": "string", "RoomId": "long" } } ``` ``` -------------------------------- ### Room Statistics Message (Type=7) Source: https://context7.com/wushuaihua520/barragegrab/llms.txt Periodically pushed room statistics. Includes real-time online users and cumulative viewers. ```json { "Type": 7, "Data": { "OnlineUserCount": 3937, "TotalUserCount": 269277, "TotalUserCountStr": "26.9万", "OnlineUserCountStr": "3937", "MsgId": 7338699901570204223, "User": null, "Content": "当前直播间人数 3937,累计直播间人数 26.9万", "RoomId": 7338657973104921378 } } ``` -------------------------------- ### Live Status Change Message (Type=8) Source: https://context7.com/wushuaihua520/barragegrab/llms.txt Pushed when the live room status changes, such as the end of the broadcast. ```json { "Type": 8, "Data": { "MsgId": 7338700002526595855, "User": null, "Content": "直播已结束", "RoomId": 7338657973104921378 } } ``` -------------------------------- ### 定义 MessageTypeEnum 与消息处理 Source: https://context7.com/wushuaihua520/barragegrab/llms.txt 定义了直播间事件的消息类型枚举,并展示了如何根据类型分发处理逻辑。 ```csharp public enum MessageTypeEnum { Member = 1, // 进入房间 Social = 2, // 关注主播 Chat = 3, // 弹幕消息 Like = 4, // 点赞 Gift = 5, // 礼物 Share = 6, // 分享直播间 RoomUserSeq = 7, // 房间人数统计 Control = 8, // 直播状态变更(如直播结束) Fansclub = 9, // 粉丝团消息 RoomStats = 10 // 直播间状态 } // 根据消息类型处理不同事件 void HandleMessage(OpenBarrageMessage message) { switch (message.Type) { case MessageTypeEnum.Chat: var chat = message.Data as DouyinMsgChat; ProcessChatMessage(chat); break; case MessageTypeEnum.Gift: var gift = message.Data as DouyinMsgGift; ProcessGiftMessage(gift); break; // ... 其他类型处理 } } ``` -------------------------------- ### Like Message (Type=4) Source: https://context7.com/wushuaihua520/barragegrab/llms.txt Details of the message when a user likes, including the number of likes in this instance and cumulative likes. ```APIDOC ## Like Message (Type=4) ### Description User likes message, including this like count and cumulative like count. ### Message Type 4 ### Data Structure ```json { "Type": 4, "Data": { "Count": "integer", "Total": "integer", "MsgId": "long", "User": { "Id": "long", "NickName": "string", "PayLevel": "integer", "FansClub": { "ClubName": "string", "Level": "integer" } }, "Content": "string", "RoomId": "long" } } ``` ``` -------------------------------- ### Douyin Live Stream Status Change Message Format Source: https://github.com/wushuaihua520/barragegrab/blob/master/README.md This JSON indicates a change in the live stream's status, such as the stream ending. It contains a message describing the status change and the room ID. ```json { "Type": 8, "Data": { "MsgId": 7338700002526595855, "User": null, "Content": "直播已结束", "RoomId": 7338657973104921378 } } ``` -------------------------------- ### Douyin Gift Message Format Source: https://github.com/wushuaihua520/barragegrab/blob/master/README.md This JSON structure represents a user sending a gift during a Douyin live stream. It details the gift, sender, receiver (if applicable), and room information. ```json { "Type": 5, "Data": { "GiftId": 2002, "GiftName": "大啤酒", "GroupId": 0, "GiftCount": 1, "RepeatCount": 0, "DiamondCount": 2, "ToUser": null, "MsgId": 7338697242632999936, "User": { "FollowingCount": 5828, "Id": 75473804556, "ShortId": 122703863, "DisplayId": "122703863", "NickName": "温馨❤️的港湾💤", "Level": 1, "PayLevel": 32, "Gender": 2, "Birthday": 0, "Telephone": null, "Avatar": "https://p11.douyinpic.com/aweme/100x100/aweme-avatar/tos-cn-i-0813_e683277c719241259afb241932527869.jpeg?from=3067671334", "SecUid": "MS4wLjABAAAAyBD6W4wd1UfvQQahxuhX8fOZxtH2TxdjHzH6y1-xyJw", "FansClub": { "ClubName": "熊家人", "Level": 3 }, "FollowerCount": 511, "FollowStatus": 0 }, "Content": "温馨❤️的港湾💤 送出 大啤酒 x 1 个", "RoomId": 7338657973104921378 } } ``` -------------------------------- ### Gift Message (Type=5) Source: https://context7.com/wushuaihua520/barragegrab/llms.txt Represents a gift sent by a user. Includes gift details, quantity, and value. ```json { "Type": 5, "Data": { "GiftId": 2002, "GiftName": "大啤酒", "GroupId": 0, "TotalCount": 1, "RepeatCount": 1, "ComboCount": 0, "GroupCount": 0, "DiamondCount": 2, "ToUser": null, "MsgId": 7338697242632999936, "User": { "FollowingCount": 5828, "Id": 75473804556, "ShortId": 122703863, "DisplayId": "122703863", "NickName": "温馨的港湾", "Level": 1, "PayLevel": 32, "Gender": 2, "Avatar": "https://p11.douyinpic.com/aweme/100x100/xxx.jpeg", "FansClub": { "ClubName": "熊家人", "Level": 3 }, "FollowerCount": 511, "FollowStatus": 0 }, "Content": "温馨的港湾 送出 大啤酒 x 1 个", "RoomId": 7338657973104921378 } } ``` -------------------------------- ### Douyin Danmaku (Barrage) Message Format Source: https://github.com/wushuaihua520/barragegrab/blob/master/README.md This JSON represents a danmaku message sent by a user in a Douyin live stream. It includes the sender's information, the message content, and room details. ```json { "Type": 3, "Data": { "MsgId": 7338697347818230818, "User": { "FollowingCount": 134, "Id": 1411400097607259, "ShortId": 2200868407, "DisplayId": "2200868407", "NickName": "雅馨💅", "Level": 0, "PayLevel": 30, "Gender": 2, "Birthday": 0, "Telephone": null, "Avatar": "https://p3.douyinpic.com/aweme/100x100/aweme-avatar/tos-cn-i-0813c001_oUHIAzME2AfjA31NAgFUpNymZDeA6AayhIsCAo.jpeg?from=3067671334", "SecUid": "MS4wLjABAAAAxKx07UstZBmcpNz4vr4r8pRbq5PYRcP98mI--SQx0c7fHVa7pmMCYFdvnlgmivty", "FansClub": { "ClubName": "熊家人", "Level": 8 }, "FollowerCount": 325, "FollowStatus": 2 }, "Content": "流量呢", "RoomId": 7338657973104921378 } } ``` -------------------------------- ### Danmaku Message (Type=3) Source: https://context7.com/wushuaihua520/barragegrab/llms.txt Represents a danmaku or chat message sent by a user. Includes message content and sender details. ```json { "Type": 3, "Data": { "MsgId": 7338697347818230818, "User": { "FollowingCount": 134, "Id": 1411400097607259, "ShortId": 2200868407, "DisplayId": "2200868407", "NickName": "雅馨", "Level": 0, "PayLevel": 30, "Gender": 2, "Avatar": "https://p3.douyinpic.com/aweme/100x100/xxx.jpeg", "SecUid": "MS4wLjABAAAA...", "FansClub": { "ClubName": "熊家人", "Level": 8 }, "FollowerCount": 325, "FollowStatus": 2 }, "Content": "主播唱得真好听", "RoomId": 7338657973104921378 } } ``` -------------------------------- ### MessageTypeEnum Source: https://context7.com/wushuaihua520/barragegrab/llms.txt An enumeration defining the types of messages that can be received from the live stream, such as chat messages, gifts, likes, and room events. ```APIDOC ## MessageTypeEnum ### Description Defines the various types of messages supported by the BarrageGrab system, used to categorize different live stream events. ### Enum Values - **Member (1)**: Represents a user entering the room. - **Social (2)**: Represents a user following the streamer. - **Chat (3)**: Represents a danmaku message. - **Like (4)**: Represents a like action. - **Gift (5)**: Represents a gift being sent. - **Share (6)**: Represents a room share action. - **RoomUserSeq (7)**: Represents statistics about room users. - **Control (8)**: Represents control messages, such as live stream status changes. - **Fansclub (9)**: Represents fan club related messages. - **RoomStats (10)**: Represents general room statistics. ### Usage Example (C#) ```csharp public enum MessageTypeEnum { Member = 1, Social = 2, Chat = 3, Like = 4, Gift = 5, Share = 6, RoomUserSeq = 7, Control = 8, Fansclub = 9, RoomStats = 10 } // Example of handling messages based on type void HandleMessage(OpenBarrageMessage message) { switch (message.Type) { case MessageTypeEnum.Chat: var chat = message.Data as DouyinMsgChat; ProcessChatMessage(chat); break; case MessageTypeEnum.Gift: var gift = message.Data as DouyinMsgGift; ProcessGiftMessage(gift); break; // ... handle other message types } } ``` ``` -------------------------------- ### Gift Message (Type=5) Source: https://context7.com/wushuaihua520/barragegrab/llms.txt Details of the message when a user sends a gift, including gift details, quantity, and value information. ```APIDOC ## Gift Message (Type=5) ### Description User sent gift message, including gift details, quantity, and value information. ### Message Type 5 ### Data Structure ```json { "Type": 5, "Data": { "GiftId": "integer", "GiftName": "string", "GroupId": "integer", "TotalCount": "integer", "RepeatCount": "integer", "ComboCount": "integer", "GroupCount": "integer", "DiamondCount": "integer", "ToUser": "object | null", "MsgId": "long", "User": { "FollowingCount": "integer", "Id": "long", "ShortId": "integer", "DisplayId": "string", "NickName": "string", "Level": "integer", "PayLevel": "integer", "Gender": "integer", "Avatar": "string", "FansClub": { "ClubName": "string", "Level": "integer" }, "FollowerCount": "integer", "FollowStatus": "integer" }, "Content": "string", "RoomId": "long" } } ``` ``` -------------------------------- ### OpenBarrageMessage Structure Source: https://context7.com/wushuaihua520/barragegrab/llms.txt The unified message structure used by BarrageGrab to represent all incoming live stream events, ensuring a consistent format across different platforms. ```APIDOC ## OpenBarrageMessage ### Description A unified message wrapper class that encapsulates the type and data of a barrage message. All platform-specific messages are converted into this format for consistent handling. ### Properties - **Type** (MessageTypeEnum): The type of the message. - **Data** (object?): The actual message data, castable to specific types based on the `Type` property. ### Example (C#) ```csharp public class OpenBarrageMessage { public MessageTypeEnum Type { get; set; } public object? Data { get; set; } } // Creating a chat message instance var chatMessage = new OpenBarrageMessage { Type = MessageTypeEnum.Chat, Data = new DouyinMsgChat { MsgId = 7338697347818230818, Content = "主播好厉害!", RoomId = 7338657973104921378, User = new DouyinUser { Id = 1411400097607259, NickName = "小明", Avatar = "https://p3.douyinpic.com/aweme/100x100/xxx.jpeg" } } }; // Serialize to JSON and broadcast string json = JsonConvert.SerializeObject(chatMessage); await wsServer.Broadcast(json); ``` ``` -------------------------------- ### Barrage Message (Type=3) Source: https://context7.com/wushuaihua520/barragegrab/llms.txt Details of the message sent by a user, including message content and sender's detailed information. ```APIDOC ## Barrage Message (Type=3) ### Description User sent barrage/chat message, including message content and sender's detailed information. ### Message Type 3 ### Data Structure ```json { "Type": 3, "Data": { "MsgId": "long", "User": { "FollowingCount": "integer", "Id": "long", "ShortId": "integer", "DisplayId": "string", "NickName": "string", "Level": "integer", "PayLevel": "integer", "Gender": "integer", "Avatar": "string", "SecUid": "string", "FansClub": { "ClubName": "string", "Level": "integer" }, "FollowerCount": "integer", "FollowStatus": "integer" }, "Content": "string", "RoomId": "long" } } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.