opt: live: show emoticon_unique

This commit is contained in:
bggRGjQaUbCoE
2024-11-04 11:08:50 +08:00
parent 42901b3c05
commit 2190336638
5 changed files with 89 additions and 29 deletions

View File

@@ -68,7 +68,7 @@ class MemberHttp {
String? accessKey = GStorage.localCache String? accessKey = GStorage.localCache
.get(LocalCacheKey.accessKey, defaultValue: {})['value']; .get(LocalCacheKey.accessKey, defaultValue: {})['value'];
Map<String, String> data = { Map<String, String> data = {
if (accessKey != null) 'access_key': accessKey, if (accessKey?.isNotEmpty == true) 'access_key': accessKey!,
'appkey': Constants.appKey, 'appkey': Constants.appKey,
'build': '1462100', 'build': '1462100',
'c_locale': 'zh_CN', 'c_locale': 'zh_CN',
@@ -115,7 +115,7 @@ class MemberHttp {
String? accessKey = GStorage.localCache String? accessKey = GStorage.localCache
.get(LocalCacheKey.accessKey, defaultValue: {})['value']; .get(LocalCacheKey.accessKey, defaultValue: {})['value'];
Map<String, String> data = { Map<String, String> data = {
if (accessKey != null) 'access_key': accessKey, if (accessKey?.isNotEmpty == true) 'access_key': accessKey!,
'appkey': Constants.appKey, 'appkey': Constants.appKey,
'build': '1462100', 'build': '1462100',
'c_locale': 'zh_CN', 'c_locale': 'zh_CN',
@@ -168,7 +168,7 @@ class MemberHttp {
String? accessKey = GStorage.localCache String? accessKey = GStorage.localCache
.get(LocalCacheKey.accessKey, defaultValue: {})['value']; .get(LocalCacheKey.accessKey, defaultValue: {})['value'];
Map<String, String> data = { Map<String, String> data = {
if (accessKey != null) 'access_key': accessKey, if (accessKey?.isNotEmpty == true) 'access_key': accessKey!,
if (aid != null) 'aid': aid.toString(), if (aid != null) 'aid': aid.toString(),
'appkey': Constants.appKey, 'appkey': Constants.appKey,
'build': '1462100', 'build': '1462100',
@@ -230,7 +230,7 @@ class MemberHttp {
String? accessKey = GStorage.localCache String? accessKey = GStorage.localCache
.get(LocalCacheKey.accessKey, defaultValue: {})['value']; .get(LocalCacheKey.accessKey, defaultValue: {})['value'];
Map<String, String> data = { Map<String, String> data = {
if (accessKey != null) 'access_key': accessKey, if (accessKey?.isNotEmpty == true) 'access_key': accessKey!,
'appkey': Constants.appKey, 'appkey': Constants.appKey,
'build': '1462100', 'build': '1462100',
'c_locale': 'zh_CN', 'c_locale': 'zh_CN',

View File

@@ -9,12 +9,14 @@ class RoomInfoModel {
int? liveStatus; int? liveStatus;
int? liveTime; int? liveTime;
PlayurlInfo? playurlInfo; PlayurlInfo? playurlInfo;
bool? isPortrait;
RoomInfoModel.fromJson(Map<String, dynamic> json) { RoomInfoModel.fromJson(Map<String, dynamic> json) {
roomId = json['room_id']; roomId = json['room_id'];
liveStatus = json['live_status']; liveStatus = json['live_status'];
liveTime = json['live_time']; liveTime = json['live_time'];
playurlInfo = PlayurlInfo.fromJson(json['playurl_info']); playurlInfo = PlayurlInfo.fromJson(json['playurl_info']);
isPortrait = json['is_portrait'];
} }
} }

View File

@@ -58,9 +58,12 @@ class LiveRoomController extends GetxController {
); );
} }
bool? isPortrait;
Future queryLiveInfo() async { Future queryLiveInfo() async {
var res = await LiveHttp.liveRoomInfo(roomId: roomId, qn: 10000); var res = await LiveHttp.liveRoomInfo(roomId: roomId, qn: 10000);
if (res['status']) { if (res['status']) {
isPortrait = res['data'].isPortrait;
List<CodecItem> codec = List<CodecItem> codec =
res['data'].playurlInfo.playurl.stream.first.format.first.codec; res['data'].playurlInfo.playurl.stream.first.format.first.codec;
CodecItem item = codec.first; CodecItem item = codec.first;

View File

@@ -2,6 +2,7 @@ import 'dart:io';
import 'package:PiliPalaX/http/live.dart'; import 'package:PiliPalaX/http/live.dart';
import 'package:PiliPalaX/pages/live_room/widgets/chat.dart'; import 'package:PiliPalaX/pages/live_room/widgets/chat.dart';
import 'package:PiliPalaX/utils/utils.dart';
import 'package:floating/floating.dart'; import 'package:floating/floating.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';
@@ -21,6 +22,7 @@ class LiveRoomPage extends StatefulWidget {
} }
class _LiveRoomPageState extends State<LiveRoomPage> { class _LiveRoomPageState extends State<LiveRoomPage> {
late final int _roomId;
final LiveRoomController _liveRoomController = Get.put(LiveRoomController()); final LiveRoomController _liveRoomController = Get.put(LiveRoomController());
PlPlayerController? plPlayerController; PlPlayerController? plPlayerController;
late Future? _futureBuilder; late Future? _futureBuilder;
@@ -31,6 +33,7 @@ class _LiveRoomPageState extends State<LiveRoomPage> {
Floating? floating; Floating? floating;
late final _isLogin = GStorage.userInfo.get('userInfoCache') != null; late final _isLogin = GStorage.userInfo.get('userInfoCache') != null;
late final _node = FocusNode();
late final _ctr = TextEditingController(); late final _ctr = TextEditingController();
void playCallBack() { void playCallBack() {
@@ -40,6 +43,7 @@ class _LiveRoomPageState extends State<LiveRoomPage> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_roomId = int.parse(Get.parameters['roomid'] ?? '-1');
PlPlayerController.setPlayCallBack(playCallBack); PlPlayerController.setPlayCallBack(playCallBack);
if (Platform.isAndroid) { if (Platform.isAndroid) {
floating = Floating(); floating = Floating();
@@ -58,6 +62,7 @@ class _LiveRoomPageState extends State<LiveRoomPage> {
void dispose() { void dispose() {
PlPlayerController.setPlayCallBack(null); PlPlayerController.setPlayCallBack(null);
floating?.dispose(); floating?.dispose();
_node.dispose();
plPlayerController?.dispose(); plPlayerController?.dispose();
_ctr.dispose(); _ctr.dispose();
super.dispose(); super.dispose();
@@ -149,12 +154,25 @@ class _LiveRoomPageState extends State<LiveRoomPage> {
return Obx( return Obx(
() => Row( () => Row(
children: [ children: [
NetworkImgLayer( GestureDetector(
width: 34, onTap: () {
height: 34, _node.unfocus();
type: 'avatar', dynamic uid = _liveRoomController
src: _liveRoomController .roomInfoH5.value.roomInfo?.uid;
.roomInfoH5.value.anchorInfo!.baseInfo!.face, Get.toNamed(
'/member?mid=$uid',
arguments: {
'heroTag': Utils.makeHeroTag(uid),
},
);
},
child: NetworkImgLayer(
width: 34,
height: 34,
type: 'avatar',
src: _liveRoomController.roomInfoH5.value
.anchorInfo!.baseInfo!.face,
),
), ),
const SizedBox(width: 10), const SizedBox(width: 10),
Column( Column(
@@ -228,19 +246,29 @@ class _LiveRoomPageState extends State<LiveRoomPage> {
verticalScreenForTwoSeconds(); verticalScreenForTwoSeconds();
} }
}, },
child: SizedBox( child: Listener(
width: Get.size.width, onPointerDown: (_) {
height: MediaQuery.of(context).orientation == _node.unfocus();
Orientation.landscape },
? Get.size.height child: SizedBox(
: Get.size.width * 9 / 16, width: Get.size.width,
child: videoPlayerPanel, height: MediaQuery.of(context).orientation ==
Orientation.landscape
? Get.size.height
: Get.size.width * 9 / 16,
child: videoPlayerPanel,
),
), ),
), ),
Expanded( Expanded(
child: LiveRoomChat( child: Listener(
roomId: int.parse(Get.parameters['roomid']!), onPointerDown: (_) {
liveRoomController: _liveRoomController, _node.unfocus();
},
child: LiveRoomChat(
roomId: _roomId,
liveRoomController: _liveRoomController,
),
), ),
), ),
Container( Container(
@@ -264,6 +292,7 @@ class _LiveRoomPageState extends State<LiveRoomPage> {
children: [ children: [
Expanded( Expanded(
child: TextField( child: TextField(
focusNode: _node,
controller: _ctr, controller: _ctr,
textInputAction: TextInputAction.send, textInputAction: TextInputAction.send,
onSubmitted: (value) { onSubmitted: (value) {

View File

@@ -6,8 +6,11 @@ import 'package:PiliPalaX/models/live/danmu_info.dart';
import 'package:PiliPalaX/pages/live_room/controller.dart'; import 'package:PiliPalaX/pages/live_room/controller.dart';
import 'package:PiliPalaX/services/loggeer.dart'; import 'package:PiliPalaX/services/loggeer.dart';
import 'package:PiliPalaX/tcp/live.dart'; import 'package:PiliPalaX/tcp/live.dart';
import 'package:PiliPalaX/utils/utils.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import '../../../utils/storage.dart'; import '../../../utils/storage.dart';
@@ -72,6 +75,23 @@ class _LiveRoomChatState extends State<LiveRoomChat> {
color: Color(0xFFAAAAAA), color: Color(0xFFAAAAAA),
fontSize: 14, fontSize: 14,
), ),
recognizer: TapGestureRecognizer()
..onTap = () {
try {
dynamic uid =
widget.liveRoomController.messages[index]
['info'][0][15]['user']['uid'];
Get.toNamed(
'/member?mid=$uid',
arguments: {
'heroTag': Utils.makeHeroTag(uid),
},
);
} catch (err) {
print(err.toString());
// SmartDialog.showToast(err.toString());
}
},
), ),
_buildMsg(widget.liveRoomController.messages[index]), _buildMsg(widget.liveRoomController.messages[index]),
], ],
@@ -153,12 +173,17 @@ class _LiveRoomChatState extends State<LiveRoomChat> {
TextSpan _buildMsg(obj) { TextSpan _buildMsg(obj) {
dynamic emots = jsonDecode(obj['info'][0][15]['extra'])['emots']; dynamic emots = jsonDecode(obj['info'][0][15]['extra'])['emots'];
if (emots != null) { dynamic uemote = obj['info'][0][13];
List list = emots.keys.map((e) { List list = [
return e.replaceAllMapped( if (emots != null) emots.keys,
RegExp(r'\[(.*?)\]'), if (uemote is Map) uemote['emoticon_unique'].replaceFirst('upower_', '')
(match) => r'\[' + match.group(1)! + r'\]', ];
); if (list.isNotEmpty) {
list = list.map((e) {
return e.toString().replaceAllMapped(
RegExp(r'\[(.*?)\]'),
(match) => r'\[' + match.group(1)! + r'\]',
);
}).toList(); }).toList();
RegExp regExp = RegExp(list.join('|')); RegExp regExp = RegExp(list.join('|'));
final List<InlineSpan> spanChildren = <InlineSpan>[]; final List<InlineSpan> spanChildren = <InlineSpan>[];
@@ -166,13 +191,14 @@ class _LiveRoomChatState extends State<LiveRoomChat> {
regExp, regExp,
onMatch: (Match match) { onMatch: (Match match) {
String key = match[0]!; String key = match[0]!;
dynamic emote = emots?[key] ?? uemote;
spanChildren.add(WidgetSpan( spanChildren.add(WidgetSpan(
child: ExcludeSemantics( child: ExcludeSemantics(
child: NetworkImgLayer( child: NetworkImgLayer(
src: emots[key]['url'], src: emote['url'],
type: 'emote', type: 'emote',
width: emots[key]['width'].toDouble(), width: emote['width'].toDouble(),
height: emots[key]['height'].toDouble(), height: emote['height'].toDouble(),
semanticsLabel: key, semanticsLabel: key,
)), )),
)); ));