Merge branch 'main' into fix
This commit is contained in:
@ -558,4 +558,11 @@ class Api {
|
|||||||
/// 系统通知标记已读
|
/// 系统通知标记已读
|
||||||
static const String systemMarkRead =
|
static const String systemMarkRead =
|
||||||
'${HttpString.messageBaseUrl}/x/sys-msg/update_cursor';
|
'${HttpString.messageBaseUrl}/x/sys-msg/update_cursor';
|
||||||
|
|
||||||
|
/// 直播间弹幕信息
|
||||||
|
static const String getDanmuInfo =
|
||||||
|
'${HttpString.liveBaseUrl}/xlive/web-room/v1/index/getDanmuInfo';
|
||||||
|
|
||||||
|
/// 直播间发送弹幕
|
||||||
|
static const String sendLiveMsg = '${HttpString.liveBaseUrl}/msg/send';
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,6 +29,7 @@ class Request {
|
|||||||
late String systemProxyPort;
|
late String systemProxyPort;
|
||||||
static final RegExp spmPrefixExp =
|
static final RegExp spmPrefixExp =
|
||||||
RegExp(r'<meta name="spm_prefix" content="([^"]+?)">');
|
RegExp(r'<meta name="spm_prefix" content="([^"]+?)">');
|
||||||
|
static late String buvid;
|
||||||
|
|
||||||
/// 设置cookie
|
/// 设置cookie
|
||||||
static setCookie() async {
|
static setCookie() async {
|
||||||
@ -70,6 +71,8 @@ class Request {
|
|||||||
final String cookieString = cookie
|
final String cookieString = cookie
|
||||||
.map((Cookie cookie) => '${cookie.name}=${cookie.value}')
|
.map((Cookie cookie) => '${cookie.name}=${cookie.value}')
|
||||||
.join('; ');
|
.join('; ');
|
||||||
|
|
||||||
|
buvid = cookie.firstWhere((e) => e.name == 'buvid3').value;
|
||||||
dio.options.headers['cookie'] = cookieString;
|
dio.options.headers['cookie'] = cookieString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -65,4 +65,56 @@ class LiveHttp {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取弹幕信息
|
||||||
|
static Future liveDanmakuInfo({roomId}) async {
|
||||||
|
var res = await Request().get(Api.getDanmuInfo, data: {
|
||||||
|
'id': roomId,
|
||||||
|
});
|
||||||
|
if (res.data['code'] == 0) {
|
||||||
|
return {
|
||||||
|
'status': true,
|
||||||
|
'data': res.data['data'],
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
'status': false,
|
||||||
|
'data': [],
|
||||||
|
'msg': res.data['message'],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 发送弹幕
|
||||||
|
static Future sendDanmaku({roomId, msg}) async {
|
||||||
|
var res = await Request().post(Api.sendLiveMsg, queryParameters: {
|
||||||
|
'bubble': 0,
|
||||||
|
'msg': msg,
|
||||||
|
'color': 16777215, // 颜色
|
||||||
|
'mode': 1, // 模式
|
||||||
|
'room_type': 0,
|
||||||
|
'jumpfrom': 71001, // 直播间来源
|
||||||
|
'reply_mid': 0,
|
||||||
|
'reply_attr': 0,
|
||||||
|
'replay_dmid': '',
|
||||||
|
'statistics': {"appId": 100, "platform": 5},
|
||||||
|
'fontsize': 25, // 字体大小
|
||||||
|
'rnd': DateTime.now().millisecondsSinceEpoch ~/ 1000, // 时间戳
|
||||||
|
'roomid': roomId,
|
||||||
|
'csrf': await Request.getCsrf(),
|
||||||
|
'csrf_token': await Request.getCsrf(),
|
||||||
|
});
|
||||||
|
if (res.data['code'] == 0) {
|
||||||
|
return {
|
||||||
|
'status': true,
|
||||||
|
'data': res.data['data'],
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
'status': false,
|
||||||
|
'data': [],
|
||||||
|
'msg': res.data['message'],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
101
lib/models/live/message.dart
Normal file
101
lib/models/live/message.dart
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
class LiveMessageModel {
|
||||||
|
// 消息类型
|
||||||
|
final LiveMessageType type;
|
||||||
|
|
||||||
|
// 用户名
|
||||||
|
final String userName;
|
||||||
|
|
||||||
|
// 信息
|
||||||
|
final String? message;
|
||||||
|
|
||||||
|
// 数据
|
||||||
|
final dynamic data;
|
||||||
|
|
||||||
|
final String? face;
|
||||||
|
final int? uid;
|
||||||
|
final Map<String, dynamic>? emots;
|
||||||
|
|
||||||
|
// 颜色
|
||||||
|
final LiveMessageColor color;
|
||||||
|
|
||||||
|
LiveMessageModel({
|
||||||
|
required this.type,
|
||||||
|
required this.userName,
|
||||||
|
required this.message,
|
||||||
|
required this.color,
|
||||||
|
this.data,
|
||||||
|
this.face,
|
||||||
|
this.uid,
|
||||||
|
this.emots,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
class LiveSuperChatMessage {
|
||||||
|
final String backgroundBottomColor;
|
||||||
|
final String backgroundColor;
|
||||||
|
final DateTime endTime;
|
||||||
|
final String face;
|
||||||
|
final String message;
|
||||||
|
final String price;
|
||||||
|
final DateTime startTime;
|
||||||
|
final String userName;
|
||||||
|
|
||||||
|
LiveSuperChatMessage({
|
||||||
|
required this.backgroundBottomColor,
|
||||||
|
required this.backgroundColor,
|
||||||
|
required this.endTime,
|
||||||
|
required this.face,
|
||||||
|
required this.message,
|
||||||
|
required this.price,
|
||||||
|
required this.startTime,
|
||||||
|
required this.userName,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
enum LiveMessageType {
|
||||||
|
// 普通留言
|
||||||
|
chat,
|
||||||
|
// 醒目留言
|
||||||
|
superChat,
|
||||||
|
//
|
||||||
|
online,
|
||||||
|
// 加入
|
||||||
|
join,
|
||||||
|
// 关注
|
||||||
|
follow,
|
||||||
|
}
|
||||||
|
|
||||||
|
class LiveMessageColor {
|
||||||
|
final int r, g, b;
|
||||||
|
LiveMessageColor(this.r, this.g, this.b);
|
||||||
|
static LiveMessageColor get white => LiveMessageColor(255, 255, 255);
|
||||||
|
static LiveMessageColor numberToColor(int intColor) {
|
||||||
|
var obj = intColor.toRadixString(16);
|
||||||
|
|
||||||
|
LiveMessageColor color = LiveMessageColor.white;
|
||||||
|
if (obj.length == 4) {
|
||||||
|
obj = "00$obj";
|
||||||
|
}
|
||||||
|
if (obj.length == 6) {
|
||||||
|
var R = int.parse(obj.substring(0, 2), radix: 16);
|
||||||
|
var G = int.parse(obj.substring(2, 4), radix: 16);
|
||||||
|
var B = int.parse(obj.substring(4, 6), radix: 16);
|
||||||
|
|
||||||
|
color = LiveMessageColor(R, G, B);
|
||||||
|
}
|
||||||
|
if (obj.length == 8) {
|
||||||
|
var R = int.parse(obj.substring(2, 4), radix: 16);
|
||||||
|
var G = int.parse(obj.substring(4, 6), radix: 16);
|
||||||
|
var B = int.parse(obj.substring(6, 8), radix: 16);
|
||||||
|
//var A = int.parse(obj.substring(0, 2), radix: 16);
|
||||||
|
color = LiveMessageColor(R, G, B);
|
||||||
|
}
|
||||||
|
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return "#${r.toRadixString(16).padLeft(2, '0')}${g.toRadixString(16).padLeft(2, '0')}${b.toRadixString(16).padLeft(2, '0')}";
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2,8 +2,9 @@ import 'package:pilipala/http/danmaku.dart';
|
|||||||
import 'package:pilipala/models/danmaku/dm.pb.dart';
|
import 'package:pilipala/models/danmaku/dm.pb.dart';
|
||||||
|
|
||||||
class PlDanmakuController {
|
class PlDanmakuController {
|
||||||
PlDanmakuController(this.cid);
|
PlDanmakuController(this.cid, this.type);
|
||||||
final int cid;
|
final int cid;
|
||||||
|
final String type;
|
||||||
Map<int, List<DanmakuElem>> dmSegMap = {};
|
Map<int, List<DanmakuElem>> dmSegMap = {};
|
||||||
// 已请求的段落标记
|
// 已请求的段落标记
|
||||||
List<bool> requestedSeg = [];
|
List<bool> requestedSeg = [];
|
||||||
|
|||||||
@ -12,11 +12,15 @@ import 'package:pilipala/utils/storage.dart';
|
|||||||
class PlDanmaku extends StatefulWidget {
|
class PlDanmaku extends StatefulWidget {
|
||||||
final int cid;
|
final int cid;
|
||||||
final PlPlayerController playerController;
|
final PlPlayerController playerController;
|
||||||
|
final String type;
|
||||||
|
final Function(DanmakuController)? createdController;
|
||||||
|
|
||||||
const PlDanmaku({
|
const PlDanmaku({
|
||||||
super.key,
|
super.key,
|
||||||
required this.cid,
|
required this.cid,
|
||||||
required this.playerController,
|
required this.playerController,
|
||||||
|
this.type = 'video',
|
||||||
|
this.createdController,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -43,9 +47,9 @@ class _PlDanmakuState extends State<PlDanmaku> {
|
|||||||
super.initState();
|
super.initState();
|
||||||
enableShowDanmaku =
|
enableShowDanmaku =
|
||||||
setting.get(SettingBoxKey.enableShowDanmaku, defaultValue: false);
|
setting.get(SettingBoxKey.enableShowDanmaku, defaultValue: false);
|
||||||
_plDanmakuController = PlDanmakuController(widget.cid);
|
_plDanmakuController = PlDanmakuController(widget.cid, widget.type);
|
||||||
if (mounted) {
|
|
||||||
playerController = widget.playerController;
|
playerController = widget.playerController;
|
||||||
|
if (mounted && widget.type == 'video') {
|
||||||
if (enableShowDanmaku || playerController.isOpenDanmu.value) {
|
if (enableShowDanmaku || playerController.isOpenDanmu.value) {
|
||||||
_plDanmakuController.initiate(
|
_plDanmakuController.initiate(
|
||||||
playerController.duration.value.inMilliseconds,
|
playerController.duration.value.inMilliseconds,
|
||||||
@ -55,6 +59,7 @@ class _PlDanmakuState extends State<PlDanmaku> {
|
|||||||
..addStatusLister(playerListener)
|
..addStatusLister(playerListener)
|
||||||
..addPositionListener(videoPositionListen);
|
..addPositionListener(videoPositionListen);
|
||||||
}
|
}
|
||||||
|
if (widget.type == 'video') {
|
||||||
playerController.isOpenDanmu.listen((p0) {
|
playerController.isOpenDanmu.listen((p0) {
|
||||||
if (p0 && !_plDanmakuController.initiated) {
|
if (p0 && !_plDanmakuController.initiated) {
|
||||||
_plDanmakuController.initiate(
|
_plDanmakuController.initiate(
|
||||||
@ -62,6 +67,7 @@ class _PlDanmakuState extends State<PlDanmaku> {
|
|||||||
playerController.position.value.inMilliseconds);
|
playerController.position.value.inMilliseconds);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
blockTypes = playerController.blockTypes;
|
blockTypes = playerController.blockTypes;
|
||||||
showArea = playerController.showArea;
|
showArea = playerController.showArea;
|
||||||
opacityVal = playerController.opacityVal;
|
opacityVal = playerController.opacityVal;
|
||||||
@ -128,6 +134,7 @@ class _PlDanmakuState extends State<PlDanmaku> {
|
|||||||
child: DanmakuView(
|
child: DanmakuView(
|
||||||
createdController: (DanmakuController e) async {
|
createdController: (DanmakuController e) async {
|
||||||
playerController.danmakuController = _controller = e;
|
playerController.danmakuController = _controller = e;
|
||||||
|
widget.createdController?.call(e);
|
||||||
},
|
},
|
||||||
option: DanmakuOption(
|
option: DanmakuOption(
|
||||||
fontSize: 15 * fontSizeVal,
|
fontSize: 15 * fontSizeVal,
|
||||||
@ -136,8 +143,7 @@ class _PlDanmakuState extends State<PlDanmaku> {
|
|||||||
hideTop: blockTypes.contains(5),
|
hideTop: blockTypes.contains(5),
|
||||||
hideScroll: blockTypes.contains(2),
|
hideScroll: blockTypes.contains(2),
|
||||||
hideBottom: blockTypes.contains(4),
|
hideBottom: blockTypes.contains(4),
|
||||||
duration:
|
duration: danmakuDurationVal / playerController.playbackSpeed,
|
||||||
danmakuDurationVal / playerController.playbackSpeed,
|
|
||||||
strokeWidth: strokeWidth,
|
strokeWidth: strokeWidth,
|
||||||
// initDuration /
|
// initDuration /
|
||||||
// (danmakuSpeedVal * widget.playerController.playbackSpeed),
|
// (danmakuSpeedVal * widget.playerController.playbackSpeed),
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import 'package:bottom_sheet/bottom_sheet.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:pilipala/common/widgets/network_img_layer.dart';
|
import 'package:pilipala/common/widgets/network_img_layer.dart';
|
||||||
@ -47,9 +48,21 @@ class FollowItem extends StatelessWidget {
|
|||||||
height: 34,
|
height: 34,
|
||||||
child: TextButton(
|
child: TextButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
await Get.bottomSheet(
|
await showFlexibleBottomSheet(
|
||||||
GroupPanel(mid: item.mid!),
|
bottomSheetColor: Colors.transparent,
|
||||||
isScrollControlled: true,
|
minHeight: 1,
|
||||||
|
initHeight: 1,
|
||||||
|
maxHeight: 1,
|
||||||
|
context: Get.context!,
|
||||||
|
builder: (BuildContext context,
|
||||||
|
ScrollController scrollController, double offset) {
|
||||||
|
return GroupPanel(
|
||||||
|
mid: item.mid!,
|
||||||
|
scrollController: scrollController,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
anchors: [1],
|
||||||
|
isSafeArea: true,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
style: TextButton.styleFrom(
|
style: TextButton.styleFrom(
|
||||||
|
|||||||
@ -1,10 +1,19 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
import 'dart:convert';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
|
import 'package:hive/hive.dart';
|
||||||
|
import 'package:ns_danmaku/ns_danmaku.dart';
|
||||||
import 'package:pilipala/http/constants.dart';
|
import 'package:pilipala/http/constants.dart';
|
||||||
|
import 'package:pilipala/http/init.dart';
|
||||||
import 'package:pilipala/http/live.dart';
|
import 'package:pilipala/http/live.dart';
|
||||||
|
import 'package:pilipala/models/live/message.dart';
|
||||||
import 'package:pilipala/models/live/quality.dart';
|
import 'package:pilipala/models/live/quality.dart';
|
||||||
import 'package:pilipala/models/live/room_info.dart';
|
import 'package:pilipala/models/live/room_info.dart';
|
||||||
import 'package:pilipala/plugin/pl_player/index.dart';
|
import 'package:pilipala/plugin/pl_player/index.dart';
|
||||||
|
import 'package:pilipala/plugin/pl_socket/index.dart';
|
||||||
|
import 'package:pilipala/utils/live.dart';
|
||||||
import '../../models/live/room_info_h5.dart';
|
import '../../models/live/room_info_h5.dart';
|
||||||
import '../../utils/storage.dart';
|
import '../../utils/storage.dart';
|
||||||
import '../../utils/video_utils.dart';
|
import '../../utils/video_utils.dart';
|
||||||
@ -24,6 +33,20 @@ class LiveRoomController extends GetxController {
|
|||||||
int? tempCurrentQn;
|
int? tempCurrentQn;
|
||||||
late List<Map<String, dynamic>> acceptQnList;
|
late List<Map<String, dynamic>> acceptQnList;
|
||||||
RxString currentQnDesc = ''.obs;
|
RxString currentQnDesc = ''.obs;
|
||||||
|
Box userInfoCache = GStrorage.userInfo;
|
||||||
|
int userId = 0;
|
||||||
|
PlSocket? plSocket;
|
||||||
|
List<String> danmuHostList = [];
|
||||||
|
String token = '';
|
||||||
|
// 弹幕消息列表
|
||||||
|
RxList<LiveMessageModel> messageList = <LiveMessageModel>[].obs;
|
||||||
|
DanmakuController? danmakuController;
|
||||||
|
// 输入控制器
|
||||||
|
TextEditingController inputController = TextEditingController();
|
||||||
|
// 加入直播间提示
|
||||||
|
RxMap<String, String> joinRoomTip = {'userName': '', 'message': ''}.obs;
|
||||||
|
// 直播间弹幕开关 默认打开
|
||||||
|
RxBool danmakuSwitch = true.obs;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
@ -43,6 +66,14 @@ class LiveRoomController extends GetxController {
|
|||||||
}
|
}
|
||||||
// CDN优化
|
// CDN优化
|
||||||
enableCDN = setting.get(SettingBoxKey.enableCDN, defaultValue: true);
|
enableCDN = setting.get(SettingBoxKey.enableCDN, defaultValue: true);
|
||||||
|
final userInfo = userInfoCache.get('userInfoCache');
|
||||||
|
if (userInfo != null && userInfo.mid != null) {
|
||||||
|
userId = userInfo.mid;
|
||||||
|
}
|
||||||
|
liveDanmakuInfo().then((value) => initSocket());
|
||||||
|
danmakuSwitch.listen((p0) {
|
||||||
|
plPlayerController.isOpenDanmu.value = p0;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
playerInit(source) async {
|
playerInit(source) async {
|
||||||
@ -61,6 +92,7 @@ class LiveRoomController extends GetxController {
|
|||||||
enableHA: true,
|
enableHA: true,
|
||||||
autoplay: true,
|
autoplay: true,
|
||||||
);
|
);
|
||||||
|
plPlayerController.isOpenDanmu.value = danmakuSwitch.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future queryLiveInfo() async {
|
Future queryLiveInfo() async {
|
||||||
@ -127,4 +159,126 @@ class LiveRoomController extends GetxController {
|
|||||||
.description;
|
.description;
|
||||||
await queryLiveInfo();
|
await queryLiveInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future liveDanmakuInfo() async {
|
||||||
|
var res = await LiveHttp.liveDanmakuInfo(roomId: roomId);
|
||||||
|
if (res['status']) {
|
||||||
|
danmuHostList = (res["data"]["host_list"] as List)
|
||||||
|
.map<String>((e) => '${e["host"]}:${e['wss_port']}')
|
||||||
|
.toList();
|
||||||
|
token = res["data"]["token"];
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 建立socket
|
||||||
|
void initSocket() async {
|
||||||
|
final wsUrl = danmuHostList.isNotEmpty
|
||||||
|
? danmuHostList.first
|
||||||
|
: "broadcastlv.chat.bilibili.com";
|
||||||
|
plSocket = PlSocket(
|
||||||
|
url: 'wss://$wsUrl/sub',
|
||||||
|
heartTime: 30,
|
||||||
|
onReadyCb: () {
|
||||||
|
joinRoom();
|
||||||
|
},
|
||||||
|
onMessageCb: (message) {
|
||||||
|
final List<LiveMessageModel>? liveMsg =
|
||||||
|
LiveUtils.decodeMessage(message);
|
||||||
|
if (liveMsg != null && liveMsg.isNotEmpty) {
|
||||||
|
if (liveMsg.first.type == LiveMessageType.online) {
|
||||||
|
print('当前直播间人气:${liveMsg.first.data}');
|
||||||
|
} else if (liveMsg.first.type == LiveMessageType.join ||
|
||||||
|
liveMsg.first.type == LiveMessageType.follow) {
|
||||||
|
// 每隔一秒依次liveMsg中的每一项赋给activeUserName
|
||||||
|
|
||||||
|
int index = 0;
|
||||||
|
Timer.periodic(const Duration(seconds: 2), (timer) {
|
||||||
|
if (index < liveMsg.length) {
|
||||||
|
if (liveMsg[index].type == LiveMessageType.join ||
|
||||||
|
liveMsg[index].type == LiveMessageType.follow) {
|
||||||
|
joinRoomTip.value = {
|
||||||
|
'userName': liveMsg[index].userName,
|
||||||
|
'message': liveMsg[index].message!,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
} else {
|
||||||
|
timer.cancel();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 过滤出聊天消息
|
||||||
|
var chatMessages =
|
||||||
|
liveMsg.where((msg) => msg.type == LiveMessageType.chat).toList();
|
||||||
|
|
||||||
|
// 添加到 messageList
|
||||||
|
messageList.addAll(chatMessages);
|
||||||
|
|
||||||
|
// 将 chatMessages 转换为 danmakuItems 列表
|
||||||
|
List<DanmakuItem> danmakuItems = chatMessages.map<DanmakuItem>((e) {
|
||||||
|
return DanmakuItem(
|
||||||
|
e.message ?? '',
|
||||||
|
color: Color.fromARGB(
|
||||||
|
255,
|
||||||
|
e.color.r,
|
||||||
|
e.color.g,
|
||||||
|
e.color.b,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}).toList();
|
||||||
|
|
||||||
|
// 添加到 danmakuController
|
||||||
|
if (danmakuSwitch.value) {
|
||||||
|
danmakuController?.addItems(danmakuItems);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onErrorCb: (e) {
|
||||||
|
print('error: $e');
|
||||||
|
},
|
||||||
|
);
|
||||||
|
await plSocket?.connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
void joinRoom() async {
|
||||||
|
var joinData = LiveUtils.encodeData(
|
||||||
|
json.encode({
|
||||||
|
"uid": userId,
|
||||||
|
"roomid": roomId,
|
||||||
|
"protover": 3,
|
||||||
|
"buvid": Request.buvid,
|
||||||
|
"platform": "web",
|
||||||
|
"type": 2,
|
||||||
|
"key": token,
|
||||||
|
}),
|
||||||
|
7,
|
||||||
|
);
|
||||||
|
plSocket?.sendMessage(joinData);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 发送弹幕
|
||||||
|
void sendMsg() async {
|
||||||
|
final msg = inputController.text;
|
||||||
|
if (msg.isEmpty) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final res = await LiveHttp.sendDanmaku(
|
||||||
|
roomId: roomId,
|
||||||
|
msg: msg,
|
||||||
|
);
|
||||||
|
if (res['status']) {
|
||||||
|
inputController.clear();
|
||||||
|
} else {
|
||||||
|
SmartDialog.showToast(res['msg']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onClose() {
|
||||||
|
plSocket?.onClose();
|
||||||
|
super.onClose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,13 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:floating/floating.dart';
|
import 'package:floating/floating.dart';
|
||||||
|
import 'package:flutter/gestures.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/rendering.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:pilipala/common/widgets/network_img_layer.dart';
|
import 'package:pilipala/common/widgets/network_img_layer.dart';
|
||||||
|
import 'package:pilipala/models/live/message.dart';
|
||||||
|
import 'package:pilipala/pages/danmaku/index.dart';
|
||||||
import 'package:pilipala/plugin/pl_player/index.dart';
|
import 'package:pilipala/plugin/pl_player/index.dart';
|
||||||
|
|
||||||
import 'controller.dart';
|
import 'controller.dart';
|
||||||
@ -16,15 +20,20 @@ class LiveRoomPage extends StatefulWidget {
|
|||||||
State<LiveRoomPage> createState() => _LiveRoomPageState();
|
State<LiveRoomPage> createState() => _LiveRoomPageState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _LiveRoomPageState extends State<LiveRoomPage> {
|
class _LiveRoomPageState extends State<LiveRoomPage>
|
||||||
|
with TickerProviderStateMixin {
|
||||||
final LiveRoomController _liveRoomController = Get.put(LiveRoomController());
|
final LiveRoomController _liveRoomController = Get.put(LiveRoomController());
|
||||||
PlPlayerController? plPlayerController;
|
late PlPlayerController plPlayerController;
|
||||||
late Future? _futureBuilder;
|
late Future? _futureBuilder;
|
||||||
late Future? _futureBuilderFuture;
|
late Future? _futureBuilderFuture;
|
||||||
|
|
||||||
bool isShowCover = true;
|
bool isShowCover = true;
|
||||||
bool isPlay = true;
|
bool isPlay = true;
|
||||||
Floating? floating;
|
Floating? floating;
|
||||||
|
final ScrollController _scrollController = ScrollController();
|
||||||
|
late AnimationController fabAnimationCtr;
|
||||||
|
bool _shouldAutoScroll = true;
|
||||||
|
final int roomId = int.parse(Get.parameters['roomid']!);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -34,6 +43,13 @@ class _LiveRoomPageState extends State<LiveRoomPage> {
|
|||||||
}
|
}
|
||||||
videoSourceInit();
|
videoSourceInit();
|
||||||
_futureBuilderFuture = _liveRoomController.queryLiveInfo();
|
_futureBuilderFuture = _liveRoomController.queryLiveInfo();
|
||||||
|
// 监听滚动事件
|
||||||
|
_scrollController.addListener(_onScroll);
|
||||||
|
fabAnimationCtr = AnimationController(
|
||||||
|
vsync: this,
|
||||||
|
duration: const Duration(milliseconds: 300),
|
||||||
|
value: 0.0,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> videoSourceInit() async {
|
Future<void> videoSourceInit() async {
|
||||||
@ -41,12 +57,52 @@ class _LiveRoomPageState extends State<LiveRoomPage> {
|
|||||||
plPlayerController = _liveRoomController.plPlayerController;
|
plPlayerController = _liveRoomController.plPlayerController;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _onScroll() {
|
||||||
|
// 反向时,展示按钮
|
||||||
|
if (_scrollController.position.userScrollDirection ==
|
||||||
|
ScrollDirection.forward) {
|
||||||
|
_shouldAutoScroll = false;
|
||||||
|
fabAnimationCtr.forward();
|
||||||
|
} else {
|
||||||
|
_shouldAutoScroll = true;
|
||||||
|
fabAnimationCtr.reverse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 监听messageList的变化,自动滚动到底部
|
||||||
|
@override
|
||||||
|
void didChangeDependencies() {
|
||||||
|
super.didChangeDependencies();
|
||||||
|
_liveRoomController.messageList.listen((_) {
|
||||||
|
if (_shouldAutoScroll) {
|
||||||
|
_scrollToBottom();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void _scrollToBottom() {
|
||||||
|
if (_scrollController.hasClients) {
|
||||||
|
_scrollController
|
||||||
|
.animateTo(
|
||||||
|
_scrollController.position.maxScrollExtent,
|
||||||
|
duration: const Duration(milliseconds: 300),
|
||||||
|
curve: Curves.easeOut,
|
||||||
|
)
|
||||||
|
.then((value) {
|
||||||
|
_shouldAutoScroll = true;
|
||||||
|
// fabAnimationCtr.forward();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
plPlayerController!.dispose();
|
plPlayerController.dispose();
|
||||||
if (floating != null) {
|
if (floating != null) {
|
||||||
floating!.dispose();
|
floating!.dispose();
|
||||||
}
|
}
|
||||||
|
_scrollController.dispose();
|
||||||
|
fabAnimationCtr.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,8 +112,9 @@ class _LiveRoomPageState extends State<LiveRoomPage> {
|
|||||||
future: _futureBuilderFuture,
|
future: _futureBuilderFuture,
|
||||||
builder: (BuildContext context, AsyncSnapshot snapshot) {
|
builder: (BuildContext context, AsyncSnapshot snapshot) {
|
||||||
if (snapshot.hasData && snapshot.data['status']) {
|
if (snapshot.hasData && snapshot.data['status']) {
|
||||||
|
plPlayerController = _liveRoomController.plPlayerController;
|
||||||
return PLVideoPlayer(
|
return PLVideoPlayer(
|
||||||
controller: plPlayerController!,
|
controller: plPlayerController,
|
||||||
bottomControl: BottomControl(
|
bottomControl: BottomControl(
|
||||||
controller: plPlayerController,
|
controller: plPlayerController,
|
||||||
liveRoomCtr: _liveRoomController,
|
liveRoomCtr: _liveRoomController,
|
||||||
@ -68,6 +125,14 @@ class _LiveRoomPageState extends State<LiveRoomPage> {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
danmuWidget: PlDanmaku(
|
||||||
|
cid: roomId,
|
||||||
|
playerController: plPlayerController,
|
||||||
|
type: 'live',
|
||||||
|
createdController: (e) {
|
||||||
|
_liveRoomController.danmakuController = e;
|
||||||
|
},
|
||||||
|
),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return const SizedBox();
|
return const SizedBox();
|
||||||
@ -80,20 +145,6 @@ class _LiveRoomPageState extends State<LiveRoomPage> {
|
|||||||
backgroundColor: Colors.black,
|
backgroundColor: Colors.black,
|
||||||
body: Stack(
|
body: Stack(
|
||||||
children: [
|
children: [
|
||||||
Positioned(
|
|
||||||
left: 0,
|
|
||||||
right: 0,
|
|
||||||
bottom: 0,
|
|
||||||
child: Opacity(
|
|
||||||
opacity: 0.8,
|
|
||||||
child: Image.asset(
|
|
||||||
'assets/images/live/default_bg.webp',
|
|
||||||
fit: BoxFit.cover,
|
|
||||||
// width: Get.width,
|
|
||||||
// height: Get.height,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Obx(
|
Obx(
|
||||||
() => Positioned(
|
() => Positioned(
|
||||||
left: 0,
|
left: 0,
|
||||||
@ -106,7 +157,7 @@ class _LiveRoomPageState extends State<LiveRoomPage> {
|
|||||||
.roomInfoH5.value.roomInfo?.appBackground !=
|
.roomInfoH5.value.roomInfo?.appBackground !=
|
||||||
null
|
null
|
||||||
? Opacity(
|
? Opacity(
|
||||||
opacity: 0.8,
|
opacity: 0.6,
|
||||||
child: NetworkImgLayer(
|
child: NetworkImgLayer(
|
||||||
width: Get.width,
|
width: Get.width,
|
||||||
height: Get.height,
|
height: Get.height,
|
||||||
@ -116,10 +167,19 @@ class _LiveRoomPageState extends State<LiveRoomPage> {
|
|||||||
'',
|
'',
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
: const SizedBox(),
|
: Opacity(
|
||||||
|
opacity: 0.6,
|
||||||
|
child: Image.asset(
|
||||||
|
'assets/images/live/default_bg.webp',
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
// width: Get.width,
|
||||||
|
// height: Get.height,
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Column(
|
Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
AppBar(
|
AppBar(
|
||||||
centerTitle: false,
|
centerTitle: false,
|
||||||
@ -179,10 +239,10 @@ class _LiveRoomPageState extends State<LiveRoomPage> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
PopScope(
|
PopScope(
|
||||||
canPop: plPlayerController?.isFullScreen.value != true,
|
canPop: plPlayerController.isFullScreen.value != true,
|
||||||
onPopInvoked: (bool didPop) {
|
onPopInvoked: (bool didPop) {
|
||||||
if (plPlayerController?.isFullScreen.value == true) {
|
if (plPlayerController.isFullScreen.value == true) {
|
||||||
plPlayerController!.triggerFullScreen(status: false);
|
plPlayerController.triggerFullScreen(status: false);
|
||||||
}
|
}
|
||||||
if (MediaQuery.of(context).orientation ==
|
if (MediaQuery.of(context).orientation ==
|
||||||
Orientation.landscape) {
|
Orientation.landscape) {
|
||||||
@ -198,8 +258,160 @@ class _LiveRoomPageState extends State<LiveRoomPage> {
|
|||||||
child: videoPlayerPanel,
|
child: videoPlayerPanel,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
// 显示消息的列表
|
||||||
|
buildMessageListUI(
|
||||||
|
context,
|
||||||
|
_liveRoomController,
|
||||||
|
_scrollController,
|
||||||
|
),
|
||||||
|
// Container(
|
||||||
|
// padding: const EdgeInsets.only(
|
||||||
|
// left: 14, right: 14, top: 4, bottom: 4),
|
||||||
|
// margin: const EdgeInsets.only(
|
||||||
|
// bottom: 6,
|
||||||
|
// left: 14,
|
||||||
|
// ),
|
||||||
|
// decoration: BoxDecoration(
|
||||||
|
// color: Colors.grey.withOpacity(0.1),
|
||||||
|
// borderRadius: const BorderRadius.all(Radius.circular(20)),
|
||||||
|
// ),
|
||||||
|
// child: Obx(
|
||||||
|
// () => AnimatedSwitcher(
|
||||||
|
// duration: const Duration(milliseconds: 300),
|
||||||
|
// transitionBuilder:
|
||||||
|
// (Widget child, Animation<double> animation) {
|
||||||
|
// return FadeTransition(opacity: animation, child: child);
|
||||||
|
// },
|
||||||
|
// child: Text.rich(
|
||||||
|
// key:
|
||||||
|
// ValueKey(_liveRoomController.joinRoomTip['userName']),
|
||||||
|
// TextSpan(
|
||||||
|
// style: const TextStyle(color: Colors.white),
|
||||||
|
// children: [
|
||||||
|
// TextSpan(
|
||||||
|
// text:
|
||||||
|
// '${_liveRoomController.joinRoomTip['userName']} ',
|
||||||
|
// style: TextStyle(
|
||||||
|
// color: Colors.white.withOpacity(0.6),
|
||||||
|
// ),
|
||||||
|
// ),
|
||||||
|
// TextSpan(
|
||||||
|
// text:
|
||||||
|
// '${_liveRoomController.joinRoomTip['message']}',
|
||||||
|
// style: const TextStyle(color: Colors.white),
|
||||||
|
// ),
|
||||||
|
// ],
|
||||||
|
// ),
|
||||||
|
// ),
|
||||||
|
// ),
|
||||||
|
// ),
|
||||||
|
// ),
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
// 弹幕输入框
|
||||||
|
Container(
|
||||||
|
padding: EdgeInsets.only(
|
||||||
|
left: 14,
|
||||||
|
right: 14,
|
||||||
|
top: 4,
|
||||||
|
bottom: MediaQuery.of(context).padding.bottom + 20),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.grey.withOpacity(0.1),
|
||||||
|
borderRadius: const BorderRadius.all(Radius.circular(20)),
|
||||||
|
border: Border(
|
||||||
|
top: BorderSide(
|
||||||
|
color: Colors.white.withOpacity(0.1),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
SizedBox(
|
||||||
|
width: 34,
|
||||||
|
height: 34,
|
||||||
|
child: Obx(
|
||||||
|
() => IconButton(
|
||||||
|
style: ButtonStyle(
|
||||||
|
padding: MaterialStateProperty.all(EdgeInsets.zero),
|
||||||
|
backgroundColor: MaterialStateProperty.resolveWith(
|
||||||
|
(Set<MaterialState> states) {
|
||||||
|
return Colors.grey.withOpacity(0.1);
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
_liveRoomController.danmakuSwitch.value =
|
||||||
|
!_liveRoomController.danmakuSwitch.value;
|
||||||
|
},
|
||||||
|
icon: Icon(
|
||||||
|
_liveRoomController.danmakuSwitch.value
|
||||||
|
? Icons.subtitles_outlined
|
||||||
|
: Icons.subtitles_off_outlined,
|
||||||
|
size: 19,
|
||||||
|
color: Colors.white,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Expanded(
|
||||||
|
child: TextField(
|
||||||
|
controller: _liveRoomController.inputController,
|
||||||
|
style:
|
||||||
|
const TextStyle(color: Colors.white, fontSize: 13),
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: '发送弹幕',
|
||||||
|
hintStyle: TextStyle(
|
||||||
|
color: Colors.white.withOpacity(0.6),
|
||||||
|
),
|
||||||
|
border: InputBorder.none,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
width: 34,
|
||||||
|
height: 34,
|
||||||
|
child: IconButton(
|
||||||
|
style: ButtonStyle(
|
||||||
|
padding: MaterialStateProperty.all(EdgeInsets.zero),
|
||||||
|
),
|
||||||
|
onPressed: () => _liveRoomController.sendMsg(),
|
||||||
|
icon: const Icon(
|
||||||
|
Icons.send,
|
||||||
|
color: Colors.white,
|
||||||
|
size: 20,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
// 定位 快速滑动到底部
|
||||||
|
Positioned(
|
||||||
|
right: 20,
|
||||||
|
bottom: MediaQuery.of(context).padding.bottom + 80,
|
||||||
|
child: SlideTransition(
|
||||||
|
position: Tween<Offset>(
|
||||||
|
begin: const Offset(0, 4),
|
||||||
|
end: const Offset(0, 0),
|
||||||
|
).animate(CurvedAnimation(
|
||||||
|
parent: fabAnimationCtr,
|
||||||
|
curve: Curves.easeInOut,
|
||||||
|
)),
|
||||||
|
child: ElevatedButton.icon(
|
||||||
|
onPressed: () {
|
||||||
|
_scrollToBottom();
|
||||||
|
},
|
||||||
|
icon: const Icon(Icons.keyboard_arrow_down), // 图标
|
||||||
|
label: const Text('新消息'), // 文字
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
// primary: Colors.blue, // 按钮背景颜色
|
||||||
|
// onPrimary: Colors.white, // 按钮文字颜色
|
||||||
|
padding: const EdgeInsets.fromLTRB(14, 12, 20, 12), // 按钮内边距
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -214,3 +426,138 @@ class _LiveRoomPageState extends State<LiveRoomPage> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget buildMessageListUI(
|
||||||
|
BuildContext context,
|
||||||
|
LiveRoomController liveRoomController,
|
||||||
|
ScrollController scrollController,
|
||||||
|
) {
|
||||||
|
return Expanded(
|
||||||
|
child: Obx(
|
||||||
|
() => MediaQuery.removePadding(
|
||||||
|
context: context,
|
||||||
|
removeTop: true,
|
||||||
|
removeBottom: true,
|
||||||
|
child: ShaderMask(
|
||||||
|
shaderCallback: (Rect bounds) {
|
||||||
|
return LinearGradient(
|
||||||
|
begin: Alignment.topCenter,
|
||||||
|
end: Alignment.bottomCenter,
|
||||||
|
colors: [
|
||||||
|
Colors.transparent,
|
||||||
|
Colors.black.withOpacity(0.5),
|
||||||
|
Colors.black,
|
||||||
|
],
|
||||||
|
stops: const [0.01, 0.05, 0.2],
|
||||||
|
).createShader(bounds);
|
||||||
|
},
|
||||||
|
blendMode: BlendMode.dstIn,
|
||||||
|
child: GestureDetector(
|
||||||
|
onTap: () {
|
||||||
|
// 键盘失去焦点
|
||||||
|
FocusScope.of(context).requestFocus(FocusNode());
|
||||||
|
},
|
||||||
|
child: ListView.builder(
|
||||||
|
controller: scrollController,
|
||||||
|
itemCount: liveRoomController.messageList.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final LiveMessageModel liveMsgItem =
|
||||||
|
liveRoomController.messageList[index];
|
||||||
|
return Align(
|
||||||
|
alignment: Alignment.centerLeft,
|
||||||
|
child: Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.grey.withOpacity(0.1),
|
||||||
|
borderRadius: const BorderRadius.all(Radius.circular(20)),
|
||||||
|
),
|
||||||
|
margin: EdgeInsets.only(
|
||||||
|
top: index == 0 ? 20.0 : 0.0,
|
||||||
|
bottom: 6.0,
|
||||||
|
left: 14.0,
|
||||||
|
right: 14.0,
|
||||||
|
),
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
vertical: 3.0,
|
||||||
|
horizontal: 10.0,
|
||||||
|
),
|
||||||
|
child: Text.rich(
|
||||||
|
TextSpan(
|
||||||
|
style: const TextStyle(color: Colors.white),
|
||||||
|
children: [
|
||||||
|
TextSpan(
|
||||||
|
text: '${liveMsgItem.userName}: ',
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.white.withOpacity(0.6),
|
||||||
|
),
|
||||||
|
recognizer: TapGestureRecognizer()
|
||||||
|
..onTap = () {
|
||||||
|
// 处理点击事件
|
||||||
|
print('Text clicked');
|
||||||
|
},
|
||||||
|
),
|
||||||
|
TextSpan(
|
||||||
|
children: [
|
||||||
|
...buildMessageTextSpan(context, liveMsgItem)
|
||||||
|
],
|
||||||
|
// text: liveMsgItem.message,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<InlineSpan> buildMessageTextSpan(
|
||||||
|
BuildContext context,
|
||||||
|
LiveMessageModel liveMsgItem,
|
||||||
|
) {
|
||||||
|
final List<InlineSpan> inlineSpanList = [];
|
||||||
|
|
||||||
|
// 是否包含表情包
|
||||||
|
if (liveMsgItem.emots == null) {
|
||||||
|
// 没有表情包的消息
|
||||||
|
inlineSpanList.add(
|
||||||
|
TextSpan(text: liveMsgItem.message ?? ''),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// 有表情包的消息 使用正则匹配 表情包用图片渲染
|
||||||
|
final List<String> emotsKeys = liveMsgItem.emots!.keys.toList();
|
||||||
|
final RegExp pattern = RegExp(emotsKeys.map(RegExp.escape).join('|'));
|
||||||
|
|
||||||
|
liveMsgItem.message?.splitMapJoin(
|
||||||
|
pattern,
|
||||||
|
onMatch: (Match match) {
|
||||||
|
final emoteItem = liveMsgItem.emots![match.group(0)];
|
||||||
|
if (emoteItem != null) {
|
||||||
|
inlineSpanList.add(
|
||||||
|
WidgetSpan(
|
||||||
|
child: NetworkImgLayer(
|
||||||
|
width: emoteItem['width'].toDouble(),
|
||||||
|
height: emoteItem['height'].toDouble(),
|
||||||
|
type: 'emote',
|
||||||
|
src: emoteItem['url'],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
},
|
||||||
|
onNonMatch: (String nonMatch) {
|
||||||
|
inlineSpanList.add(
|
||||||
|
TextSpan(text: nonMatch),
|
||||||
|
);
|
||||||
|
return nonMatch;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return inlineSpanList;
|
||||||
|
}
|
||||||
|
|||||||
@ -168,7 +168,6 @@ class _MemberPageState extends State<MemberPage>
|
|||||||
const Icon(Icons.arrow_forward_outlined, size: 19),
|
const Icon(Icons.arrow_forward_outlined, size: 19),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const Divider(height: 1, thickness: 0.1),
|
|
||||||
|
|
||||||
/// 视频
|
/// 视频
|
||||||
Obx(() => ListTile(
|
Obx(() => ListTile(
|
||||||
@ -178,7 +177,6 @@ class _MemberPageState extends State<MemberPage>
|
|||||||
trailing: const Icon(Icons.arrow_forward_outlined,
|
trailing: const Icon(Icons.arrow_forward_outlined,
|
||||||
size: 19),
|
size: 19),
|
||||||
)),
|
)),
|
||||||
const Divider(height: 1, thickness: 0.1),
|
|
||||||
|
|
||||||
/// 他的收藏夹
|
/// 他的收藏夹
|
||||||
Obx(() => ListTile(
|
Obx(() => ListTile(
|
||||||
@ -188,13 +186,11 @@ class _MemberPageState extends State<MemberPage>
|
|||||||
trailing: const Icon(Icons.arrow_forward_outlined,
|
trailing: const Icon(Icons.arrow_forward_outlined,
|
||||||
size: 19),
|
size: 19),
|
||||||
)),
|
)),
|
||||||
const Divider(height: 1, thickness: 0.1),
|
|
||||||
|
|
||||||
/// 专栏
|
/// 专栏
|
||||||
Obx(() => ListTile(
|
Obx(() => ListTile(
|
||||||
title: Text(
|
title: Text(
|
||||||
'${_memberController.isOwner.value ? '我' : 'Ta'}的专栏'))),
|
'${_memberController.isOwner.value ? '我' : 'Ta'}的专栏'))),
|
||||||
const Divider(height: 1, thickness: 0.1),
|
|
||||||
|
|
||||||
/// 合集
|
/// 合集
|
||||||
Obx(() => ListTile(
|
Obx(() => ListTile(
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:bottom_sheet/bottom_sheet.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||||
@ -517,9 +518,21 @@ class VideoIntroController extends GetxController {
|
|||||||
|
|
||||||
// 设置关注分组
|
// 设置关注分组
|
||||||
void setFollowGroup() {
|
void setFollowGroup() {
|
||||||
Get.bottomSheet(
|
showFlexibleBottomSheet(
|
||||||
GroupPanel(mid: videoDetail.value.owner!.mid!),
|
bottomSheetColor: Colors.transparent,
|
||||||
isScrollControlled: true,
|
minHeight: 0.6,
|
||||||
|
initHeight: 0.6,
|
||||||
|
maxHeight: 1,
|
||||||
|
context: Get.context!,
|
||||||
|
builder: (BuildContext context, ScrollController scrollController,
|
||||||
|
double offset) {
|
||||||
|
return GroupPanel(
|
||||||
|
mid: videoDetail.value.owner!.mid!,
|
||||||
|
scrollController: scrollController,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
anchors: [0.6, 1],
|
||||||
|
isSafeArea: true,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,6 @@
|
|||||||
|
import 'dart:ffi';
|
||||||
|
|
||||||
|
import 'package:bottom_sheet/bottom_sheet.dart';
|
||||||
import 'package:easy_debounce/easy_throttle.dart';
|
import 'package:easy_debounce/easy_throttle.dart';
|
||||||
import 'package:expandable/expandable.dart';
|
import 'package:expandable/expandable.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
@ -215,37 +218,35 @@ class _VideoInfoState extends State<VideoInfo> with TickerProviderStateMixin {
|
|||||||
if (!videoIntroController.hasFav.value) {
|
if (!videoIntroController.hasFav.value) {
|
||||||
videoIntroController.actionFavVideo(type: 'default');
|
videoIntroController.actionFavVideo(type: 'default');
|
||||||
} else {
|
} else {
|
||||||
showModalBottomSheet(
|
_showFavPanel();
|
||||||
context: context,
|
|
||||||
useRootNavigator: true,
|
|
||||||
isScrollControlled: true,
|
|
||||||
builder: (BuildContext context) {
|
|
||||||
return FavPanel(ctr: videoIntroController);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
showModalBottomSheet(
|
_showFavPanel();
|
||||||
context: context,
|
|
||||||
useRootNavigator: true,
|
|
||||||
isScrollControlled: true,
|
|
||||||
builder: (BuildContext context) {
|
|
||||||
return FavPanel(ctr: videoIntroController);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} else if (type != 'longPress') {
|
} else if (type != 'longPress') {
|
||||||
showModalBottomSheet(
|
_showFavPanel();
|
||||||
context: context,
|
|
||||||
useRootNavigator: true,
|
|
||||||
isScrollControlled: true,
|
|
||||||
builder: (BuildContext context) {
|
|
||||||
return FavPanel(ctr: videoIntroController);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _showFavPanel() {
|
||||||
|
showFlexibleBottomSheet(
|
||||||
|
bottomSheetColor: Colors.transparent,
|
||||||
|
minHeight: 0.6,
|
||||||
|
initHeight: 0.6,
|
||||||
|
maxHeight: 1,
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context, ScrollController scrollController,
|
||||||
|
double offset) {
|
||||||
|
return FavPanel(
|
||||||
|
ctr: videoIntroController,
|
||||||
|
scrollController: scrollController,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
anchors: [0.6, 1],
|
||||||
|
isSafeArea: true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// 视频介绍
|
// 视频介绍
|
||||||
showIntroDetail() {
|
showIntroDetail() {
|
||||||
feedBack();
|
feedBack();
|
||||||
@ -613,6 +614,9 @@ class _VideoInfoState extends State<VideoInfo> with TickerProviderStateMixin {
|
|||||||
}
|
}
|
||||||
_controller.reverse();
|
_controller.reverse();
|
||||||
},
|
},
|
||||||
|
onTapCancel: () {
|
||||||
|
_controller.reverse();
|
||||||
|
},
|
||||||
borderRadius: StyleString.mdRadius,
|
borderRadius: StyleString.mdRadius,
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
width: (Get.size.width - 24) / 5,
|
width: (Get.size.width - 24) / 5,
|
||||||
|
|||||||
@ -6,8 +6,9 @@ import 'package:pilipala/utils/feed_back.dart';
|
|||||||
import 'package:pilipala/utils/storage.dart';
|
import 'package:pilipala/utils/storage.dart';
|
||||||
|
|
||||||
class FavPanel extends StatefulWidget {
|
class FavPanel extends StatefulWidget {
|
||||||
const FavPanel({super.key, this.ctr});
|
const FavPanel({super.key, this.ctr, this.scrollController});
|
||||||
final dynamic ctr;
|
final dynamic ctr;
|
||||||
|
final ScrollController? scrollController;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<FavPanel> createState() => _FavPanelState();
|
State<FavPanel> createState() => _FavPanelState();
|
||||||
@ -15,31 +16,39 @@ class FavPanel extends StatefulWidget {
|
|||||||
|
|
||||||
class _FavPanelState extends State<FavPanel> {
|
class _FavPanelState extends State<FavPanel> {
|
||||||
final Box<dynamic> localCache = GStrorage.localCache;
|
final Box<dynamic> localCache = GStrorage.localCache;
|
||||||
late double sheetHeight;
|
|
||||||
late Future _futureBuilderFuture;
|
late Future _futureBuilderFuture;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
sheetHeight = localCache.get('sheetHeight');
|
|
||||||
_futureBuilderFuture = widget.ctr!.queryVideoInFolder();
|
_futureBuilderFuture = widget.ctr!.queryVideoInFolder();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return Container(
|
||||||
height: sheetHeight,
|
clipBehavior: Clip.hardEdge,
|
||||||
|
decoration: BoxDecoration(
|
||||||
color: Theme.of(context).colorScheme.surface,
|
color: Theme.of(context).colorScheme.surface,
|
||||||
|
borderRadius: const BorderRadius.only(
|
||||||
|
topLeft: Radius.circular(16),
|
||||||
|
topRight: Radius.circular(16),
|
||||||
|
),
|
||||||
|
),
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
AppBar(
|
AppBar(
|
||||||
centerTitle: false,
|
centerTitle: false,
|
||||||
elevation: 0,
|
elevation: 0,
|
||||||
leading: IconButton(
|
automaticallyImplyLeading: false,
|
||||||
onPressed: () => Get.back(),
|
leadingWidth: 0,
|
||||||
icon: const Icon(Icons.close_outlined)),
|
title: Text(
|
||||||
title:
|
'选择收藏夹',
|
||||||
Text('添加到收藏夹', style: Theme.of(context).textTheme.titleMedium),
|
style: Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.titleMedium!
|
||||||
|
.copyWith(fontWeight: FontWeight.bold),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Material(
|
child: Material(
|
||||||
@ -51,22 +60,22 @@ class _FavPanelState extends State<FavPanel> {
|
|||||||
if (data['status']) {
|
if (data['status']) {
|
||||||
return Obx(
|
return Obx(
|
||||||
() => ListView.builder(
|
() => ListView.builder(
|
||||||
|
controller: widget.scrollController,
|
||||||
itemCount:
|
itemCount:
|
||||||
widget.ctr!.favFolderData.value.list!.length,
|
widget.ctr!.favFolderData.value.list!.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
|
final item =
|
||||||
|
widget.ctr!.favFolderData.value.list![index];
|
||||||
return ListTile(
|
return ListTile(
|
||||||
onTap: () => widget.ctr!.onChoose(
|
onTap: () => widget.ctr!
|
||||||
widget.ctr!.favFolderData.value.list![index]
|
.onChoose(item.favState != 1, index),
|
||||||
.favState !=
|
|
||||||
1,
|
|
||||||
index),
|
|
||||||
dense: true,
|
dense: true,
|
||||||
leading: const Icon(Icons.folder_outlined),
|
leading: const Icon(Icons.folder_outlined),
|
||||||
minLeadingWidth: 0,
|
minLeadingWidth: 0,
|
||||||
title: Text(widget.ctr!.favFolderData.value
|
title: Text(widget.ctr!.favFolderData.value
|
||||||
.list![index].title!),
|
.list![index].title!),
|
||||||
subtitle: Text(
|
subtitle: Text(
|
||||||
'${widget.ctr!.favFolderData.value.list![index].mediaCount}个内容',
|
'${item.mediaCount}个内容 ',
|
||||||
),
|
),
|
||||||
trailing: Transform.scale(
|
trailing: Transform.scale(
|
||||||
scale: 0.9,
|
scale: 0.9,
|
||||||
@ -132,7 +141,7 @@ class _FavPanelState extends State<FavPanel> {
|
|||||||
backgroundColor:
|
backgroundColor:
|
||||||
Theme.of(context).colorScheme.primary, // 设置按钮背景色
|
Theme.of(context).colorScheme.primary, // 设置按钮背景色
|
||||||
),
|
),
|
||||||
child: const Text('完成'),
|
child: const Text('确认选择'),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@ -10,7 +10,8 @@ import 'package:pilipala/utils/storage.dart';
|
|||||||
|
|
||||||
class GroupPanel extends StatefulWidget {
|
class GroupPanel extends StatefulWidget {
|
||||||
final int? mid;
|
final int? mid;
|
||||||
const GroupPanel({super.key, this.mid});
|
final ScrollController scrollController;
|
||||||
|
const GroupPanel({super.key, this.mid, required this.scrollController});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<GroupPanel> createState() => _GroupPanelState();
|
State<GroupPanel> createState() => _GroupPanelState();
|
||||||
@ -18,7 +19,6 @@ class GroupPanel extends StatefulWidget {
|
|||||||
|
|
||||||
class _GroupPanelState extends State<GroupPanel> {
|
class _GroupPanelState extends State<GroupPanel> {
|
||||||
final Box<dynamic> localCache = GStrorage.localCache;
|
final Box<dynamic> localCache = GStrorage.localCache;
|
||||||
late double sheetHeight;
|
|
||||||
late Future _futureBuilderFuture;
|
late Future _futureBuilderFuture;
|
||||||
late List<MemberTagItemModel> tagsList;
|
late List<MemberTagItemModel> tagsList;
|
||||||
bool showDefault = true;
|
bool showDefault = true;
|
||||||
@ -26,7 +26,6 @@ class _GroupPanelState extends State<GroupPanel> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
sheetHeight = localCache.get('sheetHeight');
|
|
||||||
_futureBuilderFuture = MemberHttp.followUpTags();
|
_futureBuilderFuture = MemberHttp.followUpTags();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,8 +55,14 @@ class _GroupPanelState extends State<GroupPanel> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return Container(
|
||||||
height: sheetHeight,
|
clipBehavior: Clip.hardEdge,
|
||||||
|
decoration: BoxDecoration(
|
||||||
color: Theme.of(context).colorScheme.surface,
|
color: Theme.of(context).colorScheme.surface,
|
||||||
|
borderRadius: const BorderRadius.only(
|
||||||
|
topLeft: Radius.circular(16),
|
||||||
|
topRight: Radius.circular(16),
|
||||||
|
),
|
||||||
|
),
|
||||||
child: Column(
|
child: Column(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
AppBar(
|
AppBar(
|
||||||
@ -79,6 +84,7 @@ class _GroupPanelState extends State<GroupPanel> {
|
|||||||
if (data['status']) {
|
if (data['status']) {
|
||||||
tagsList = data['data'];
|
tagsList = data['data'];
|
||||||
return ListView.builder(
|
return ListView.builder(
|
||||||
|
controller: widget.scrollController,
|
||||||
itemCount: data['data'].length,
|
itemCount: data['data'].length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
return ListTile(
|
return ListTile(
|
||||||
|
|||||||
@ -16,11 +16,14 @@ import 'package:pilipala/pages/main/index.dart';
|
|||||||
import 'package:pilipala/pages/video/detail/index.dart';
|
import 'package:pilipala/pages/video/detail/index.dart';
|
||||||
import 'package:pilipala/pages/video/detail/reply_new/index.dart';
|
import 'package:pilipala/pages/video/detail/reply_new/index.dart';
|
||||||
import 'package:pilipala/plugin/pl_gallery/index.dart';
|
import 'package:pilipala/plugin/pl_gallery/index.dart';
|
||||||
|
import 'package:pilipala/plugin/pl_popup/index.dart';
|
||||||
import 'package:pilipala/utils/app_scheme.dart';
|
import 'package:pilipala/utils/app_scheme.dart';
|
||||||
import 'package:pilipala/utils/feed_back.dart';
|
import 'package:pilipala/utils/feed_back.dart';
|
||||||
|
import 'package:pilipala/utils/id_utils.dart';
|
||||||
import 'package:pilipala/utils/storage.dart';
|
import 'package:pilipala/utils/storage.dart';
|
||||||
import 'package:pilipala/utils/url_utils.dart';
|
import 'package:pilipala/utils/url_utils.dart';
|
||||||
import 'package:pilipala/utils/utils.dart';
|
import 'package:pilipala/utils/utils.dart';
|
||||||
|
import 'reply_save.dart';
|
||||||
import 'zan.dart';
|
import 'zan.dart';
|
||||||
|
|
||||||
Box setting = GStrorage.setting;
|
Box setting = GStrorage.setting;
|
||||||
@ -33,6 +36,7 @@ class ReplyItem extends StatelessWidget {
|
|||||||
this.showReplyRow = true,
|
this.showReplyRow = true,
|
||||||
this.replyReply,
|
this.replyReply,
|
||||||
this.replyType,
|
this.replyType,
|
||||||
|
this.replySave = false,
|
||||||
super.key,
|
super.key,
|
||||||
});
|
});
|
||||||
final ReplyItemModel? replyItem;
|
final ReplyItemModel? replyItem;
|
||||||
@ -41,6 +45,7 @@ class ReplyItem extends StatelessWidget {
|
|||||||
final bool? showReplyRow;
|
final bool? showReplyRow;
|
||||||
final Function? replyReply;
|
final Function? replyReply;
|
||||||
final ReplyType? replyType;
|
final ReplyType? replyType;
|
||||||
|
final bool? replySave;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -48,19 +53,28 @@ class ReplyItem extends StatelessWidget {
|
|||||||
child: InkWell(
|
child: InkWell(
|
||||||
// 点击整个评论区 评论详情/回复
|
// 点击整个评论区 评论详情/回复
|
||||||
onTap: () {
|
onTap: () {
|
||||||
|
if (replySave!) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
feedBack();
|
feedBack();
|
||||||
if (replyReply != null) {
|
if (replyReply != null) {
|
||||||
replyReply!(replyItem, null, replyItem!.replies!.isNotEmpty);
|
replyReply!(replyItem, null, replyItem!.replies!.isNotEmpty);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLongPress: () {
|
onLongPress: () {
|
||||||
|
if (replySave!) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
feedBack();
|
feedBack();
|
||||||
showModalBottomSheet(
|
showModalBottomSheet(
|
||||||
context: context,
|
context: context,
|
||||||
useRootNavigator: true,
|
useRootNavigator: true,
|
||||||
isScrollControlled: true,
|
isScrollControlled: true,
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
return MorePanel(item: replyItem);
|
return MorePanel(
|
||||||
|
item: replyItem,
|
||||||
|
mainFloor: true,
|
||||||
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -233,7 +247,7 @@ class ReplyItem extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
// 操作区域
|
// 操作区域
|
||||||
bottonAction(context, replyItem!.replyControl),
|
bottonAction(context, replyItem!.replyControl, replySave),
|
||||||
// 一楼的评论
|
// 一楼的评论
|
||||||
if ((replyItem!.replyControl!.isShow! ||
|
if ((replyItem!.replyControl!.isShow! ||
|
||||||
replyItem!.replies!.isNotEmpty) &&
|
replyItem!.replies!.isNotEmpty) &&
|
||||||
@ -254,7 +268,7 @@ class ReplyItem extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 感谢、回复、复制
|
// 感谢、回复、复制
|
||||||
Widget bottonAction(BuildContext context, replyControl) {
|
Widget bottonAction(BuildContext context, replyControl, replySave) {
|
||||||
ColorScheme colorScheme = Theme.of(context).colorScheme;
|
ColorScheme colorScheme = Theme.of(context).colorScheme;
|
||||||
TextTheme textTheme = Theme.of(context).textTheme;
|
TextTheme textTheme = Theme.of(context).textTheme;
|
||||||
return Row(
|
return Row(
|
||||||
@ -287,6 +301,7 @@ class ReplyItem extends StatelessWidget {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
child: Row(children: [
|
child: Row(children: [
|
||||||
|
if (!replySave!) ...[
|
||||||
Icon(Icons.reply,
|
Icon(Icons.reply,
|
||||||
size: 18, color: colorScheme.outline.withOpacity(0.8)),
|
size: 18, color: colorScheme.outline.withOpacity(0.8)),
|
||||||
const SizedBox(width: 3),
|
const SizedBox(width: 3),
|
||||||
@ -296,6 +311,15 @@ class ReplyItem extends StatelessWidget {
|
|||||||
fontSize: textTheme.labelMedium!.fontSize,
|
fontSize: textTheme.labelMedium!.fontSize,
|
||||||
color: colorScheme.outline,
|
color: colorScheme.outline,
|
||||||
),
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
if (replySave!)
|
||||||
|
Text(
|
||||||
|
IdUtils.av2bv(replyItem!.oid!),
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: textTheme.labelMedium!.fontSize,
|
||||||
|
color: colorScheme.outline,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
),
|
),
|
||||||
@ -1008,7 +1032,12 @@ InlineSpan buildContent(
|
|||||||
|
|
||||||
class MorePanel extends StatelessWidget {
|
class MorePanel extends StatelessWidget {
|
||||||
final dynamic item;
|
final dynamic item;
|
||||||
const MorePanel({super.key, required this.item});
|
final bool mainFloor;
|
||||||
|
const MorePanel({
|
||||||
|
super.key,
|
||||||
|
required this.item,
|
||||||
|
this.mainFloor = false,
|
||||||
|
});
|
||||||
|
|
||||||
Future<dynamic> menuActionHandler(String type) async {
|
Future<dynamic> menuActionHandler(String type) async {
|
||||||
String message = item.content.message ?? item.content;
|
String message = item.content.message ?? item.content;
|
||||||
@ -1030,6 +1059,13 @@ class MorePanel extends StatelessWidget {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
case 'save':
|
||||||
|
Get.back();
|
||||||
|
Navigator.push(
|
||||||
|
Get.context!,
|
||||||
|
PlPopupRoute(child: ReplySave(replyItem: item)),
|
||||||
|
);
|
||||||
|
break;
|
||||||
// case 'block':
|
// case 'block':
|
||||||
// SmartDialog.showToast('加入黑名单');
|
// SmartDialog.showToast('加入黑名单');
|
||||||
// break;
|
// break;
|
||||||
@ -1080,6 +1116,13 @@ class MorePanel extends StatelessWidget {
|
|||||||
leading: const Icon(Icons.copy_outlined, size: 19),
|
leading: const Icon(Icons.copy_outlined, size: 19),
|
||||||
title: Text('自由复制', style: textTheme.titleSmall),
|
title: Text('自由复制', style: textTheme.titleSmall),
|
||||||
),
|
),
|
||||||
|
if (mainFloor && item.content.pictures.isEmpty)
|
||||||
|
ListTile(
|
||||||
|
onTap: () async => await menuActionHandler('save'),
|
||||||
|
minLeadingWidth: 0,
|
||||||
|
leading: const Icon(Icons.save_alt_rounded, size: 19),
|
||||||
|
title: Text('本地保存', style: textTheme.titleSmall),
|
||||||
|
),
|
||||||
// ListTile(
|
// ListTile(
|
||||||
// onTap: () async => await menuActionHandler('block'),
|
// onTap: () async => await menuActionHandler('block'),
|
||||||
// minLeadingWidth: 0,
|
// minLeadingWidth: 0,
|
||||||
|
|||||||
148
lib/pages/video/detail/reply/widgets/reply_save.dart
Normal file
148
lib/pages/video/detail/reply/widgets/reply_save.dart
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
import 'dart:math';
|
||||||
|
import 'dart:typed_data';
|
||||||
|
import 'dart:ui';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/rendering.dart';
|
||||||
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
|
import 'package:pilipala/models/video/reply/item.dart';
|
||||||
|
import 'package:pilipala/pages/video/detail/reply/widgets/reply_item.dart';
|
||||||
|
import 'package:saver_gallery/saver_gallery.dart';
|
||||||
|
|
||||||
|
class ReplySave extends StatefulWidget {
|
||||||
|
final ReplyItemModel? replyItem;
|
||||||
|
const ReplySave({required this.replyItem, super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<ReplySave> createState() => _ReplySaveState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ReplySaveState extends State<ReplySave> {
|
||||||
|
final _boundaryKey = GlobalKey();
|
||||||
|
|
||||||
|
void _generatePicWidget() async {
|
||||||
|
SmartDialog.showLoading(msg: '保存中');
|
||||||
|
try {
|
||||||
|
RenderRepaintBoundary boundary = _boundaryKey.currentContext!
|
||||||
|
.findRenderObject() as RenderRepaintBoundary;
|
||||||
|
var image = await boundary.toImage(pixelRatio: 3);
|
||||||
|
ByteData? byteData = await image.toByteData(format: ImageByteFormat.png);
|
||||||
|
Uint8List pngBytes = byteData!.buffer.asUint8List();
|
||||||
|
String picName =
|
||||||
|
"plpl_reply_${DateTime.now().toString().replaceAll(RegExp(r'[- :]'), '').split('.').first}";
|
||||||
|
final result = await SaverGallery.saveImage(
|
||||||
|
Uint8List.fromList(pngBytes),
|
||||||
|
name: '$picName.png',
|
||||||
|
androidRelativePath: "Pictures/PiliPala",
|
||||||
|
androidExistNotSave: false,
|
||||||
|
);
|
||||||
|
if (result.isSuccess) {
|
||||||
|
SmartDialog.showToast('保存成功');
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
print(err);
|
||||||
|
} finally {
|
||||||
|
SmartDialog.dismiss();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Widget> _createWidgets(int count, Widget Function() builder) {
|
||||||
|
return List<Widget>.generate(count, (_) => Expanded(child: builder()));
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Widget> _createColumnWidgets() {
|
||||||
|
return _createWidgets(3, () => Row(children: _createRowWidgets()));
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Widget> _createRowWidgets() {
|
||||||
|
return _createWidgets(
|
||||||
|
4,
|
||||||
|
() => Center(
|
||||||
|
child: Transform.rotate(
|
||||||
|
angle: pi / 10,
|
||||||
|
child: const Text(
|
||||||
|
'PiliPala',
|
||||||
|
style: TextStyle(
|
||||||
|
color: Color(0x08000000),
|
||||||
|
fontSize: 18,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
decoration: TextDecoration.none,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return SafeArea(
|
||||||
|
top: false,
|
||||||
|
bottom: false,
|
||||||
|
child: BackdropFilter(
|
||||||
|
filter: ImageFilter.blur(sigmaX: 4.0, sigmaY: 4.0),
|
||||||
|
child: Container(
|
||||||
|
width: Get.width,
|
||||||
|
height: Get.height,
|
||||||
|
padding: EdgeInsets.fromLTRB(
|
||||||
|
0,
|
||||||
|
MediaQuery.of(context).padding.top + 4,
|
||||||
|
0,
|
||||||
|
MediaQuery.of(context).padding.bottom + 4,
|
||||||
|
),
|
||||||
|
color: Colors.black54,
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Container(
|
||||||
|
clipBehavior: Clip.antiAlias,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
borderRadius: BorderRadius.circular(20),
|
||||||
|
),
|
||||||
|
child: Center(
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
child: RepaintBoundary(
|
||||||
|
key: _boundaryKey,
|
||||||
|
child: IntrinsicHeight(
|
||||||
|
child: Stack(
|
||||||
|
children: [
|
||||||
|
ReplyItem(
|
||||||
|
replyItem: widget.replyItem,
|
||||||
|
showReplyRow: false,
|
||||||
|
replySave: true,
|
||||||
|
),
|
||||||
|
Positioned.fill(
|
||||||
|
child: Column(
|
||||||
|
children: _createColumnWidgets(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 20),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
FilledButton(
|
||||||
|
onPressed: () => Get.back(),
|
||||||
|
child: const Text('取消'),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 40),
|
||||||
|
FilledButton(
|
||||||
|
onPressed: _generatePicWidget,
|
||||||
|
child: const Text('保存'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -84,7 +84,7 @@ class ChatItem extends StatelessWidget {
|
|||||||
emojiMap[e['text']] = e['url'];
|
emojiMap[e['text']] = e['url'];
|
||||||
}
|
}
|
||||||
text.splitMapJoin(
|
text.splitMapJoin(
|
||||||
RegExp(r"\[.+?\]"),
|
RegExp(r"\[[^\[\]]+\]"),
|
||||||
onMatch: (Match match) {
|
onMatch: (Match match) {
|
||||||
final String emojiKey = match[0]!;
|
final String emojiKey = match[0]!;
|
||||||
if (emojiMap.containsKey(emojiKey)) {
|
if (emojiMap.containsKey(emojiKey)) {
|
||||||
@ -95,6 +95,17 @@ class ChatItem extends StatelessWidget {
|
|||||||
src: emojiMap[emojiKey]!,
|
src: emojiMap[emojiKey]!,
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
|
} else {
|
||||||
|
children.add(
|
||||||
|
TextSpan(
|
||||||
|
text: emojiKey,
|
||||||
|
style: TextStyle(
|
||||||
|
color: textColor(context),
|
||||||
|
letterSpacing: 0.6,
|
||||||
|
height: 1.5,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
@ -109,13 +120,13 @@ class ChatItem extends StatelessWidget {
|
|||||||
return '';
|
return '';
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
return RichText(
|
return SelectableText.rich(
|
||||||
text: TextSpan(
|
TextSpan(
|
||||||
children: children,
|
children: children,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return Text(
|
return SelectableText(
|
||||||
text,
|
text,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
letterSpacing: 0.6,
|
letterSpacing: 0.6,
|
||||||
@ -133,7 +144,7 @@ class ChatItem extends StatelessWidget {
|
|||||||
case MsgType.pic_card:
|
case MsgType.pic_card:
|
||||||
return SystemNotice2(item: item);
|
return SystemNotice2(item: item);
|
||||||
case MsgType.notify_text:
|
case MsgType.notify_text:
|
||||||
return Text(
|
return SelectableText(
|
||||||
jsonDecode(content['content'])
|
jsonDecode(content['content'])
|
||||||
.map((m) => m['text'] as String)
|
.map((m) => m['text'] as String)
|
||||||
.join("\n"),
|
.join("\n"),
|
||||||
@ -530,7 +541,7 @@ class SystemNotice extends StatelessWidget {
|
|||||||
Divider(
|
Divider(
|
||||||
color: Theme.of(context).colorScheme.primary.withOpacity(0.05),
|
color: Theme.of(context).colorScheme.primary.withOpacity(0.05),
|
||||||
),
|
),
|
||||||
Text(
|
SelectableText(
|
||||||
content['text'],
|
content['text'],
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
|
|||||||
107
lib/plugin/pl_socket/index.dart
Normal file
107
lib/plugin/pl_socket/index.dart
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:pilipala/utils/live.dart';
|
||||||
|
import 'package:web_socket_channel/io.dart';
|
||||||
|
import 'package:web_socket_channel/web_socket_channel.dart';
|
||||||
|
|
||||||
|
enum SocketStatus {
|
||||||
|
connected,
|
||||||
|
failed,
|
||||||
|
closed,
|
||||||
|
}
|
||||||
|
|
||||||
|
class PlSocket {
|
||||||
|
SocketStatus status = SocketStatus.closed;
|
||||||
|
// 链接
|
||||||
|
final String url;
|
||||||
|
// 心跳时间
|
||||||
|
final int heartTime;
|
||||||
|
// 监听初始化完成
|
||||||
|
final Function? onReadyCb;
|
||||||
|
// 监听关闭
|
||||||
|
final Function? onCloseCb;
|
||||||
|
// 监听异常
|
||||||
|
final Function? onErrorCb;
|
||||||
|
// 监听消息
|
||||||
|
final Function? onMessageCb;
|
||||||
|
// 请求头
|
||||||
|
final Map<String, dynamic>? headers;
|
||||||
|
|
||||||
|
PlSocket({
|
||||||
|
required this.url,
|
||||||
|
required this.heartTime,
|
||||||
|
this.onReadyCb,
|
||||||
|
this.onCloseCb,
|
||||||
|
this.onErrorCb,
|
||||||
|
this.onMessageCb,
|
||||||
|
this.headers,
|
||||||
|
});
|
||||||
|
|
||||||
|
WebSocketChannel? channel;
|
||||||
|
StreamSubscription<dynamic>? channelStreamSub;
|
||||||
|
|
||||||
|
// 建立连接
|
||||||
|
Future connect() async {
|
||||||
|
// 连接之前关闭上次连接
|
||||||
|
onClose();
|
||||||
|
try {
|
||||||
|
channel = IOWebSocketChannel.connect(
|
||||||
|
url,
|
||||||
|
connectTimeout: const Duration(seconds: 15),
|
||||||
|
headers: null,
|
||||||
|
);
|
||||||
|
await channel?.ready;
|
||||||
|
onReady();
|
||||||
|
} catch (err) {
|
||||||
|
connect();
|
||||||
|
onError(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 初始化完成
|
||||||
|
void onReady() {
|
||||||
|
status = SocketStatus.connected;
|
||||||
|
onReadyCb?.call();
|
||||||
|
channelStreamSub = channel?.stream.listen((message) {
|
||||||
|
onMessageCb?.call(message);
|
||||||
|
}, onDone: () {
|
||||||
|
// 流被关闭
|
||||||
|
print('结束了');
|
||||||
|
}, onError: (err) {
|
||||||
|
onError(err);
|
||||||
|
});
|
||||||
|
// 每30s发送心跳
|
||||||
|
Timer.periodic(Duration(seconds: heartTime), (timer) {
|
||||||
|
if (status == SocketStatus.connected) {
|
||||||
|
sendMessage(LiveUtils.encodeData(
|
||||||
|
"",
|
||||||
|
2,
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
timer.cancel();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 连接关闭
|
||||||
|
void onClose() {
|
||||||
|
status = SocketStatus.closed;
|
||||||
|
onCloseCb?.call();
|
||||||
|
channelStreamSub?.cancel();
|
||||||
|
channel?.sink.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 连接异常
|
||||||
|
void onError(err) {
|
||||||
|
onErrorCb?.call(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 接收消息
|
||||||
|
void onMessage() {}
|
||||||
|
|
||||||
|
void sendMessage(dynamic message) {
|
||||||
|
if (status == SocketStatus.connected) {
|
||||||
|
channel?.sink.add(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
117
lib/utils/binary_writer.dart
Normal file
117
lib/utils/binary_writer.dart
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
|
class BinaryWriter {
|
||||||
|
List<int> buffer;
|
||||||
|
int position = 0;
|
||||||
|
BinaryWriter(this.buffer);
|
||||||
|
int get length => buffer.length;
|
||||||
|
|
||||||
|
void writeBytes(List<int> list) {
|
||||||
|
buffer.addAll(list);
|
||||||
|
position += list.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeInt(int value, int len, {Endian endian = Endian.big}) {
|
||||||
|
var bytes = _createByteData(len);
|
||||||
|
switch (len) {
|
||||||
|
case 1:
|
||||||
|
bytes.setUint8(0, value.toUnsigned(8));
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
bytes.setInt16(0, value, endian);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
bytes.setInt32(0, value, endian);
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
bytes.setInt64(0, value, endian);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw ArgumentError('Invalid length for writeInt: $len');
|
||||||
|
}
|
||||||
|
_addBytesToBuffer(bytes, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeDouble(double value, int len, {Endian endian = Endian.big}) {
|
||||||
|
var bytes = _createByteData(len);
|
||||||
|
switch (len) {
|
||||||
|
case 4:
|
||||||
|
bytes.setFloat32(0, value, endian);
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
bytes.setFloat64(0, value, endian);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw ArgumentError('Invalid length for writeDouble: $len');
|
||||||
|
}
|
||||||
|
_addBytesToBuffer(bytes, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
ByteData _createByteData(int len) {
|
||||||
|
var b = Uint8List(len).buffer;
|
||||||
|
return ByteData.view(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _addBytesToBuffer(ByteData bytes, int len) {
|
||||||
|
buffer.addAll(bytes.buffer.asUint8List());
|
||||||
|
position += len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class BinaryReader {
|
||||||
|
Uint8List buffer;
|
||||||
|
int position = 0;
|
||||||
|
BinaryReader(this.buffer);
|
||||||
|
int get length => buffer.length;
|
||||||
|
|
||||||
|
int read() {
|
||||||
|
return buffer[position++];
|
||||||
|
}
|
||||||
|
|
||||||
|
int readInt(int len, {Endian endian = Endian.big}) {
|
||||||
|
var bytes = _getBytes(len);
|
||||||
|
var data = ByteData.view(bytes.buffer);
|
||||||
|
switch (len) {
|
||||||
|
case 1:
|
||||||
|
return data.getUint8(0);
|
||||||
|
case 2:
|
||||||
|
return data.getInt16(0, endian);
|
||||||
|
case 4:
|
||||||
|
return data.getInt32(0, endian);
|
||||||
|
case 8:
|
||||||
|
return data.getInt64(0, endian);
|
||||||
|
default:
|
||||||
|
throw ArgumentError('Invalid length for readInt: $len');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int readByte({Endian endian = Endian.big}) => readInt(1, endian: endian);
|
||||||
|
int readShort({Endian endian = Endian.big}) => readInt(2, endian: endian);
|
||||||
|
int readInt32({Endian endian = Endian.big}) => readInt(4, endian: endian);
|
||||||
|
int readLong({Endian endian = Endian.big}) => readInt(8, endian: endian);
|
||||||
|
|
||||||
|
Uint8List readBytes(int len) {
|
||||||
|
var bytes = _getBytes(len);
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
double readFloat(int len, {Endian endian = Endian.big}) {
|
||||||
|
var bytes = _getBytes(len);
|
||||||
|
var data = ByteData.view(bytes.buffer);
|
||||||
|
switch (len) {
|
||||||
|
case 4:
|
||||||
|
return data.getFloat32(0, endian);
|
||||||
|
case 8:
|
||||||
|
return data.getFloat64(0, endian);
|
||||||
|
default:
|
||||||
|
throw ArgumentError('Invalid length for readFloat: $len');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Uint8List _getBytes(int len) {
|
||||||
|
var bytes =
|
||||||
|
Uint8List.fromList(buffer.getRange(position, position + len).toList());
|
||||||
|
position += len;
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -57,7 +57,7 @@ Future imageSaveDialog(context, videoItem, closeFn) {
|
|||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Text(
|
child: SelectableText(
|
||||||
videoItem.title! as String,
|
videoItem.title! as String,
|
||||||
style: Theme.of(context).textTheme.titleSmall,
|
style: Theme.of(context).textTheme.titleSmall,
|
||||||
),
|
),
|
||||||
|
|||||||
196
lib/utils/live.dart
Normal file
196
lib/utils/live.dart
Normal file
@ -0,0 +1,196 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
import 'dart:io';
|
||||||
|
import 'dart:typed_data';
|
||||||
|
import 'package:brotli/brotli.dart';
|
||||||
|
import 'package:pilipala/models/live/message.dart';
|
||||||
|
import 'package:pilipala/utils/binary_writer.dart';
|
||||||
|
|
||||||
|
class LiveUtils {
|
||||||
|
static List<int> encodeData(String msg, int action) {
|
||||||
|
var data = utf8.encode(msg);
|
||||||
|
//头部长度固定16
|
||||||
|
var length = data.length + 16;
|
||||||
|
var buffer = Uint8List(length);
|
||||||
|
|
||||||
|
var writer = BinaryWriter([]);
|
||||||
|
|
||||||
|
//数据包长度
|
||||||
|
writer.writeInt(buffer.length, 4);
|
||||||
|
//数据包头部长度,固定16
|
||||||
|
writer.writeInt(16, 2);
|
||||||
|
|
||||||
|
//协议版本,0=JSON,1=Int32,2=Buffer
|
||||||
|
writer.writeInt(0, 2);
|
||||||
|
|
||||||
|
//操作类型
|
||||||
|
writer.writeInt(action, 4);
|
||||||
|
|
||||||
|
//数据包头部长度,固定1
|
||||||
|
|
||||||
|
writer.writeInt(1, 4);
|
||||||
|
|
||||||
|
writer.writeBytes(data);
|
||||||
|
|
||||||
|
return writer.buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
static List<LiveMessageModel>? decodeMessage(List<int> data) {
|
||||||
|
try {
|
||||||
|
//操作类型。3=心跳回应,内容为房间人气值;5=通知,弹幕、广播等全部信息;8=进房回应,空
|
||||||
|
int operation = readInt(data, 8, 4);
|
||||||
|
//内容
|
||||||
|
var body = data.skip(16).toList();
|
||||||
|
if (operation == 3) {
|
||||||
|
var online = readInt(body, 0, 4);
|
||||||
|
final LiveMessageModel liveMsg = LiveMessageModel(
|
||||||
|
type: LiveMessageType.online,
|
||||||
|
userName: '',
|
||||||
|
message: '',
|
||||||
|
color: LiveMessageColor.white,
|
||||||
|
data: online,
|
||||||
|
);
|
||||||
|
return [liveMsg];
|
||||||
|
} else if (operation == 5) {
|
||||||
|
//协议版本。0为JSON,可以直接解析;1为房间人气值,Body为4位Int32;2为压缩过Buffer,需要解压再处理
|
||||||
|
int protocolVersion = readInt(data, 6, 2);
|
||||||
|
if (protocolVersion == 2) {
|
||||||
|
body = zlib.decode(body);
|
||||||
|
} else if (protocolVersion == 3) {
|
||||||
|
body = brotli.decode(body);
|
||||||
|
}
|
||||||
|
|
||||||
|
var text = utf8.decode(body, allowMalformed: true);
|
||||||
|
|
||||||
|
var group =
|
||||||
|
text.split(RegExp(r"[\x00-\x1f]+", unicode: true, multiLine: true));
|
||||||
|
List<LiveMessageModel> messages = [];
|
||||||
|
for (var item
|
||||||
|
in group.where((x) => x.length > 2 && x.startsWith('{'))) {
|
||||||
|
if (parseMessage(item) is LiveMessageModel) {
|
||||||
|
messages.add(parseMessage(item)!);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return messages;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
print(e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
static LiveMessageModel? parseMessage(String jsonMessage) {
|
||||||
|
try {
|
||||||
|
var obj = json.decode(jsonMessage);
|
||||||
|
var cmd = obj["cmd"].toString();
|
||||||
|
if (cmd.contains("DANMU_MSG")) {
|
||||||
|
if (obj["info"] != null && obj["info"].length != 0) {
|
||||||
|
var message = obj["info"][1].toString();
|
||||||
|
var color = asT<int?>(obj["info"][0][3]) ?? 0;
|
||||||
|
if (obj["info"][2] != null && obj["info"][2].length != 0) {
|
||||||
|
var extra = obj["info"][0][15]['extra'];
|
||||||
|
var user = obj["info"][0][15]['user']['base'];
|
||||||
|
Map<String, dynamic> extraMap = jsonDecode(extra);
|
||||||
|
final int userId = obj["info"][2][0];
|
||||||
|
final LiveMessageModel liveMsg = LiveMessageModel(
|
||||||
|
type: LiveMessageType.chat,
|
||||||
|
userName: user['name'],
|
||||||
|
message: message,
|
||||||
|
color: color == 0
|
||||||
|
? LiveMessageColor.white
|
||||||
|
: LiveMessageColor.numberToColor(color),
|
||||||
|
face: user['face'],
|
||||||
|
uid: userId,
|
||||||
|
emots: extraMap['emots'],
|
||||||
|
);
|
||||||
|
return liveMsg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (cmd == "SUPER_CHAT_MESSAGE") {
|
||||||
|
if (obj["data"] == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
final data = obj["data"];
|
||||||
|
final userInfo = data["user_info"];
|
||||||
|
final String backgroundBottomColor =
|
||||||
|
data["background_bottom_color"].toString();
|
||||||
|
final String backgroundColor = data["background_color"].toString();
|
||||||
|
final DateTime endTime =
|
||||||
|
DateTime.fromMillisecondsSinceEpoch(data["end_time"] * 1000);
|
||||||
|
final String face = "${userInfo["face"]}@200w.jpg";
|
||||||
|
final String message = data["message"].toString();
|
||||||
|
final String price = data["price"];
|
||||||
|
final DateTime startTime =
|
||||||
|
DateTime.fromMillisecondsSinceEpoch(data["start_time"] * 1000);
|
||||||
|
final String userName = userInfo["uname"].toString();
|
||||||
|
|
||||||
|
final LiveMessageModel liveMsg = LiveMessageModel(
|
||||||
|
type: LiveMessageType.superChat,
|
||||||
|
userName: "SUPER_CHAT_MESSAGE",
|
||||||
|
message: "SUPER_CHAT_MESSAGE",
|
||||||
|
color: LiveMessageColor.white,
|
||||||
|
data: {
|
||||||
|
"backgroundBottomColor": backgroundBottomColor,
|
||||||
|
"backgroundColor": backgroundColor,
|
||||||
|
"endTime": endTime,
|
||||||
|
"face": face,
|
||||||
|
"message": message,
|
||||||
|
"price": price,
|
||||||
|
"startTime": startTime,
|
||||||
|
"userName": userName,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return liveMsg;
|
||||||
|
} else if (cmd == 'INTERACT_WORD') {
|
||||||
|
if (obj["data"] == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
final data = obj["data"];
|
||||||
|
final String userName = data['uname'];
|
||||||
|
final int msgType = data['msg_type'];
|
||||||
|
final LiveMessageModel liveMsg = LiveMessageModel(
|
||||||
|
type: msgType == 1 ? LiveMessageType.join : LiveMessageType.follow,
|
||||||
|
userName: userName,
|
||||||
|
message: msgType == 1 ? '进入直播间' : '关注了主播',
|
||||||
|
color: LiveMessageColor.white,
|
||||||
|
);
|
||||||
|
return liveMsg;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
print(e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
static T? asT<T>(dynamic value) {
|
||||||
|
if (value is T) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int readInt(List<int> buffer, int start, int len) {
|
||||||
|
var data = _getByteData(buffer, start, len);
|
||||||
|
return _readIntFromByteData(data, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
static ByteData _getByteData(List<int> buffer, int start, int len) {
|
||||||
|
var bytes =
|
||||||
|
Uint8List.fromList(buffer.getRange(start, start + len).toList());
|
||||||
|
return ByteData.view(bytes.buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int _readIntFromByteData(ByteData data, int len) {
|
||||||
|
switch (len) {
|
||||||
|
case 1:
|
||||||
|
return data.getUint8(0);
|
||||||
|
case 2:
|
||||||
|
return data.getInt16(0, Endian.big);
|
||||||
|
case 4:
|
||||||
|
return data.getInt32(0, Endian.big);
|
||||||
|
case 8:
|
||||||
|
return data.getInt64(0, Endian.big);
|
||||||
|
default:
|
||||||
|
throw ArgumentError('Invalid length: $len');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
30
pubspec.lock
30
pubspec.lock
@ -113,6 +113,30 @@ packages:
|
|||||||
url: "https://pub.flutter-io.cn"
|
url: "https://pub.flutter-io.cn"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.1"
|
version: "2.1.1"
|
||||||
|
bottom_inset_observer:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: bottom_inset_observer
|
||||||
|
sha256: cbfb01e0e07cc4922052701786d5e607765a6f54e1844f41061abf8744519a7d
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "3.1.0"
|
||||||
|
bottom_sheet:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: bottom_sheet
|
||||||
|
sha256: efd28f52357d23e1c01eaeb45466b407f1e29318305bd6d10baf814fda18bd7e
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "4.0.4"
|
||||||
|
brotli:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: brotli
|
||||||
|
sha256: "7f891558ed779aab2bed874f0a36b8123f9ff3f19cf6efbee89e18ed294945ae"
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "0.6.0"
|
||||||
build:
|
build:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -1656,13 +1680,13 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "0.5.1"
|
version: "0.5.1"
|
||||||
web_socket_channel:
|
web_socket_channel:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: web_socket_channel
|
name: web_socket_channel
|
||||||
sha256: d88238e5eac9a42bb43ca4e721edba3c08c6354d4a53063afaa568516217621b
|
sha256: "58c6666b342a38816b2e7e50ed0f1e261959630becd4c879c4f26bfa14aa5a42"
|
||||||
url: "https://pub.flutter-io.cn"
|
url: "https://pub.flutter-io.cn"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.4.0"
|
version: "2.4.5"
|
||||||
webview_cookie_manager:
|
webview_cookie_manager:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
|||||||
@ -146,6 +146,9 @@ dependencies:
|
|||||||
lottie: ^3.1.2
|
lottie: ^3.1.2
|
||||||
# 二维码
|
# 二维码
|
||||||
qr_flutter: ^4.1.0
|
qr_flutter: ^4.1.0
|
||||||
|
bottom_sheet: ^4.0.4
|
||||||
|
web_socket_channel: ^2.4.5
|
||||||
|
brotli: ^0.6.0
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|||||||
Reference in New Issue
Block a user