@@ -2,14 +2,10 @@ import 'dart:io';
22import 'dart:async' ;
33import 'dart:convert' ;
44import 'proto/douyin.pb.dart' ;
5- import 'package:crypto/crypto.dart' ;
6- import 'package:flutter_js/flutter_js.dart' ;
75import 'package:pure_live/core/site/douyin_site.dart' ;
8- import 'package:pure_live/common/utils/js_engine.dart' ;
96import 'package:pure_live/common/models/live_message.dart' ;
107import 'package:pure_live/core/common/web_socket_util.dart' ;
118import 'package:pure_live/core/interface/live_danmaku.dart' ;
12- import 'package:pure_live/core/common/http_client.dart' as http;
139
1410class DouyinDanmakuArgs {
1511 final String webRid;
@@ -41,17 +37,13 @@ class DouyinDanmaku implements LiveDanmaku {
4137 Future start (dynamic args) async {
4238 danmakuArgs = args as DouyinDanmakuArgs ;
4339 var ts = DateTime .now ().millisecondsSinceEpoch;
44- JsEngine .init ();
45- await JsEngine .loadDouyinSdk ();
46- var xMsStub = getMsStub (danmakuArgs.roomId, danmakuArgs.userId);
47- JsEvalResult jsEvalResult = await JsEngine .evaluateAsync ("get_sign('$xMsStub ')" );
4840 var uri = Uri .parse (serverUrl).replace (
4941 scheme: "wss" ,
5042 queryParameters: {
5143 "app_name" : "douyin_web" ,
5244 "version_code" : "180800" ,
53- "webcast_sdk_version" : "1.0.14-beta .0" ,
54- "update_version_code" : "1.0.14-beta .0" ,
45+ "webcast_sdk_version" : "1.3 .0" ,
46+ "update_version_code" : "1.3 .0" ,
5547 "compress" : "gzip" ,
5648 // "internal_ext":
5749 // "internal_src:dim|wss_push_room_id:${danmakuArgs.roomId}|wss_push_did:${danmakuArgs.userId}|dim_log_id:20230626152702E8F63662383A350588E1|fetch_time:1687764422114|seq:1|wss_info:0-1687764422114-0-0|wrds_kvs:WebcastRoomRankMessage-1687764036509597990_InputPanelComponentSyncData-1687736682345173033_WebcastRoomStatsMessage-1687764414427812578",
@@ -79,18 +71,22 @@ class DouyinDanmaku implements LiveDanmaku {
7971 "identity" : "audience" ,
8072 "room_id" : danmakuArgs.roomId,
8173 "heartbeatDuration" : "0" ,
82- "signature" : jsEvalResult.stringResult,
74+ // "signature": "00000000"
8375 },
8476 );
8577
86- // var sign = await getSignature(danmakuArgs.roomId, danmakuArgs.userId);
78+ var sign = await getSignature (danmakuArgs.roomId, danmakuArgs.userId);
8779
88- var url = "$uri " ;
80+ var url = "$uri &signature=$ sign " ;
8981 var backupUrl = url.replaceAll ("webcast3-ws-web-lq" , "webcast5-ws-web-lf" );
9082 webScoketUtils = WebScoketUtils (
9183 url: url,
9284 backupUrl: backupUrl,
93- headers: {"User-Agnet" : DouyinSite .kDefaultUserAgent, "Cookie" : danmakuArgs.cookie},
85+ headers: {
86+ "User-Agnet" : DouyinSite .kDefaultUserAgent,
87+ "Cookie" : danmakuArgs.cookie,
88+ "Origin" : "https://live.douyin.com" ,
89+ },
9490 heartBeatTime: heartbeatTime,
9591 onMessage: (e) {
9692 decodeMessage (e);
@@ -119,9 +115,7 @@ class DouyinDanmaku implements LiveDanmaku {
119115 webScoketUtils? .sendMessage (obj.writeToBuffer ());
120116 }
121117
122- void decodeMessage (List <int > args) {
123- // CoreLog.i(args.toString());
124-
118+ void decodeMessage (dynamic args) {
125119 var wssPackage = PushFrame .fromBuffer (args);
126120
127121 var logId = wssPackage.logId;
@@ -156,25 +150,6 @@ class DouyinDanmaku implements LiveDanmaku {
156150 );
157151 }
158152
159- /// 获取Websocket签名
160- /// - [roomId] 房间ID, 例如:7382735338101328680
161- /// - [uniqueId] 用户唯一ID, 例如:7273033021933946427
162- ///
163- /// 服务端代码:https://github.com/lovelyyoshino/douyin_python,请自行部署后使用
164- Future <String > getSignature (String roomId, String uniqueId) async {
165- try {
166- var signResult = await http.HttpClient .instance.postJson (
167- "https://dy.nsapps.cn/signature" ,
168- queryParameters: {},
169- header: {"Content-Type" : "application/json" },
170- data: {"roomId" : roomId, "uniqueId" : uniqueId},
171- );
172- return signResult["data" ]["signature" ];
173- } catch (e) {
174- return "" ;
175- }
176- }
177-
178153 void unPackWebcastRoomUserSeqMessage (List <int > payload) {
179154 var roomUserSeqMessage = RoomUserSeqMessage .fromBuffer (payload);
180155
@@ -210,27 +185,11 @@ class DouyinDanmaku implements LiveDanmaku {
210185 webScoketUtils? .close ();
211186 }
212187
213- String getMsStub (String liveRoomRealId, String userUniqueId) {
214- Map <String , dynamic > params = {
215- "live_id" : "1" ,
216- "aid" : "6383" ,
217- "version_code" : 180800 ,
218- "webcast_sdk_version" : '1.0.14-beta.0' ,
219- "room_id" : liveRoomRealId,
220- "sub_room_id" : "" ,
221- "sub_channel_id" : "" ,
222- "did_rule" : "3" ,
223- "user_unique_id" : userUniqueId,
224- "device_platform" : "web" ,
225- "device_type" : "" ,
226- "ac" : "" ,
227- "identity" : "audience" ,
228- };
229-
230- String sigParams = params.entries.map ((e) => '${e .key }=${e .value }' ).join (',' );
231-
232- var bytes = utf8.encode (sigParams);
233- var digest = md5.convert (bytes);
234- return digest.toString ();
188+ Future <String > Function (String , String ) getSignature = (roomId, uniqueId) async {
189+ return "" ;
190+ };
191+
192+ void setSignatureFunction (Future <String > Function (String , String ) func) {
193+ getSignature = func;
235194 }
236195}
0 commit comments