mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
feat: send live msg
This commit is contained in:
@@ -283,6 +283,8 @@ class Api {
|
||||
static const String liveRoomInfo =
|
||||
'${HttpString.liveBaseUrl}/xlive/web-room/v2/index/getRoomPlayInfo';
|
||||
|
||||
static const String sendLiveMsg = '${HttpString.liveBaseUrl}/msg/send';
|
||||
|
||||
// 直播间详情 H5
|
||||
static const String liveRoomInfoH5 =
|
||||
'${HttpString.liveBaseUrl}/xlive/web-room/v1/index/getH5InfoByRoom';
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import 'package:PiliPalaX/common/constants.dart';
|
||||
import 'package:PiliPalaX/http/loading_state.dart';
|
||||
import 'package:PiliPalaX/models/live/danmu_info.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import '../models/live/item.dart';
|
||||
import '../models/live/room_info.dart';
|
||||
import '../models/live/room_info_h5.dart';
|
||||
@@ -25,6 +27,49 @@ class LiveHttp {
|
||||
}
|
||||
}
|
||||
|
||||
static Future sendLiveMsg({
|
||||
roomId,
|
||||
msg,
|
||||
}) async {
|
||||
dynamic csrf = await Request.getCsrf();
|
||||
var res = await Request().post(
|
||||
Api.sendLiveMsg,
|
||||
data: {
|
||||
'bubble': 0,
|
||||
'msg': msg,
|
||||
'color': 16777215,
|
||||
'mode': 1,
|
||||
'room_type': 0,
|
||||
'jumpfrom': 71000,
|
||||
'reply_mid': 0,
|
||||
'reply_attr': 0,
|
||||
'replay_dmid': '',
|
||||
'statistics': Constants.statistics,
|
||||
'reply_type': 0,
|
||||
'reply_uname': '',
|
||||
'fontsize': 25,
|
||||
'rnd': DateTime.now().millisecondsSinceEpoch ~/ 1000,
|
||||
'roomid': roomId,
|
||||
'csrf': csrf,
|
||||
'csrf_token': csrf,
|
||||
},
|
||||
options: Options(
|
||||
contentType: Headers.formUrlEncodedContentType,
|
||||
),
|
||||
);
|
||||
if (res.data['code'] == 0) {
|
||||
return {
|
||||
'status': true,
|
||||
'data': res.data['data'],
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
'status': false,
|
||||
'msg': res.data['message'],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
static Future liveRoomInfo({roomId, qn}) async {
|
||||
var res = await Request().get(Api.liveRoomInfo, data: {
|
||||
'room_id': roomId,
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:PiliPalaX/http/live.dart';
|
||||
import 'package:PiliPalaX/pages/live_room/widgets/chat.dart';
|
||||
import 'package:floating/floating.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:PiliPalaX/common/widgets/network_img_layer.dart';
|
||||
import 'package:PiliPalaX/plugin/pl_player/index.dart';
|
||||
@@ -28,6 +30,9 @@ class _LiveRoomPageState extends State<LiveRoomPage> {
|
||||
bool isPlay = true;
|
||||
Floating? floating;
|
||||
|
||||
late final _isLogin = GStorage.userInfo.get('userInfoCache') != null;
|
||||
late final _ctr = TextEditingController();
|
||||
|
||||
void playCallBack() {
|
||||
plPlayerController?.play();
|
||||
}
|
||||
@@ -54,6 +59,7 @@ class _LiveRoomPageState extends State<LiveRoomPage> {
|
||||
PlPlayerController.setPlayCallBack(null);
|
||||
floating?.dispose();
|
||||
plPlayerController?.dispose();
|
||||
_ctr.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -233,7 +239,60 @@ class _LiveRoomPageState extends State<LiveRoomPage> {
|
||||
),
|
||||
Expanded(
|
||||
child: LiveRoomChat(
|
||||
roomId: int.parse(Get.parameters['roomid']!)))
|
||||
roomId: int.parse(Get.parameters['roomid']!),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
padding: EdgeInsets.only(
|
||||
left: 16,
|
||||
top: 10,
|
||||
right: 16,
|
||||
bottom: 25 + MediaQuery.of(context).padding.bottom,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: Radius.circular(20),
|
||||
topRight: Radius.circular(20),
|
||||
),
|
||||
border: Border(
|
||||
top: BorderSide(color: Color(0x1AFFFFFF)),
|
||||
),
|
||||
color: Color(0x1AFFFFFF),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _ctr,
|
||||
textInputAction: TextInputAction.send,
|
||||
onSubmitted: (value) {
|
||||
if (value.isNotEmpty) {
|
||||
_onSendMsg(value);
|
||||
}
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
border: InputBorder.none,
|
||||
hintText: '发送弹幕',
|
||||
hintStyle: TextStyle(
|
||||
color: Theme.of(context).colorScheme.outline,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
if (_ctr.text.isNotEmpty) {
|
||||
_onSendMsg(_ctr.text);
|
||||
}
|
||||
},
|
||||
icon: Icon(
|
||||
Icons.send,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
@@ -249,4 +308,19 @@ class _LiveRoomPageState extends State<LiveRoomPage> {
|
||||
return childWhenDisabled;
|
||||
}
|
||||
}
|
||||
|
||||
void _onSendMsg(msg) async {
|
||||
if (!_isLogin) {
|
||||
SmartDialog.showToast('未登录');
|
||||
return;
|
||||
}
|
||||
dynamic res = await LiveHttp.sendLiveMsg(
|
||||
roomId: _liveRoomController.roomId, msg: msg);
|
||||
if (res['status']) {
|
||||
_ctr.clear();
|
||||
SmartDialog.showToast('发送成功');
|
||||
} else {
|
||||
SmartDialog.showToast(res['msg']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ class _LiveRoomChatState extends State<LiveRoomChat> {
|
||||
padding: EdgeInsets.only(
|
||||
left: 10,
|
||||
right: 10,
|
||||
bottom: MediaQuery.of(context).padding.bottom,
|
||||
bottom: 5,
|
||||
),
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
|
||||
Reference in New Issue
Block a user