enables recording on web
This commit is contained in:
parent
c5677e4562
commit
c2245f045f
3 changed files with 57 additions and 8 deletions
|
|
@ -808,11 +808,18 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
builder: (c) => const RecordingDialog(),
|
||||
);
|
||||
if (result == null) return;
|
||||
final audioFile = File(result.path);
|
||||
// #Pangea
|
||||
// enable web recording
|
||||
// final audioFile = File(result.path);
|
||||
// final file = MatrixAudioFile(
|
||||
// bytes: audioFile.readAsBytesSync(),
|
||||
// name: audioFile.path,
|
||||
// );
|
||||
final file = MatrixAudioFile(
|
||||
bytes: audioFile.readAsBytesSync(),
|
||||
name: audioFile.path,
|
||||
bytes: result.bytes,
|
||||
name: result.path,
|
||||
);
|
||||
// Pangea#
|
||||
await room.sendFileEvent(
|
||||
file,
|
||||
inReplyTo: replyEvent,
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/pangea/utils/update_version_dialog.dart';
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:record/record.dart';
|
||||
import 'package:wakelock_plus/wakelock_plus.dart';
|
||||
|
|
@ -39,9 +42,15 @@ class RecordingDialogState extends State<RecordingDialog> {
|
|||
|
||||
Future<void> startRecording() async {
|
||||
try {
|
||||
final tempDir = await getTemporaryDirectory();
|
||||
// #Pangea
|
||||
// enable recording on web
|
||||
// final tempDir = await getTemporaryDirectory();
|
||||
// final path = _recordedPath =
|
||||
// '${tempDir.path}/recording${DateTime.now().microsecondsSinceEpoch}.${RecordingDialog.recordingFileType}';
|
||||
final tempDirPath = kIsWeb ? "." : (await getTemporaryDirectory()).path;
|
||||
_recordedPath =
|
||||
'${tempDir.path}/recording${DateTime.now().microsecondsSinceEpoch}.${RecordingDialog.recordingFileType}';
|
||||
'$tempDirPath/recording${DateTime.now().microsecondsSinceEpoch}.${RecordingDialog.recordingFileType}';
|
||||
// Pangea#
|
||||
|
||||
final result = await _audioRecorder.hasPermission();
|
||||
if (result != true) {
|
||||
|
|
@ -105,9 +114,25 @@ class RecordingDialogState extends State<RecordingDialog> {
|
|||
|
||||
void _stopAndSend() async {
|
||||
_recorderSubscription?.cancel();
|
||||
await _audioRecorder.stop();
|
||||
// #Pangea
|
||||
// await _audioRecorder.stop();
|
||||
final outputPath = await _audioRecorder.stop();
|
||||
// Pangea#
|
||||
final path = _recordedPath;
|
||||
if (path == null) throw ('Recording failed!');
|
||||
|
||||
// #Pangea
|
||||
Uint8List bytes;
|
||||
if (kIsWeb) {
|
||||
if (outputPath == null) throw ('Recording failed!');
|
||||
final response = await http.get(Uri.parse(outputPath));
|
||||
bytes = response.bodyBytes;
|
||||
} else {
|
||||
final audioFile = File(path);
|
||||
bytes = audioFile.readAsBytesSync();
|
||||
}
|
||||
// Pangea#
|
||||
|
||||
const waveCount = AudioPlayerWidget.wavesCount;
|
||||
final step = amplitudeTimeline.length < waveCount
|
||||
? 1
|
||||
|
|
@ -121,6 +146,9 @@ class RecordingDialogState extends State<RecordingDialog> {
|
|||
path: path,
|
||||
duration: _duration.inMilliseconds,
|
||||
waveform: waveform,
|
||||
// #Pangea
|
||||
bytes: bytes,
|
||||
// Pangea#
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
@ -231,11 +259,17 @@ class RecordingResult {
|
|||
final String path;
|
||||
final int duration;
|
||||
final List<int> waveform;
|
||||
// #Pangea
|
||||
final Uint8List bytes;
|
||||
// Pangea#
|
||||
|
||||
const RecordingResult({
|
||||
required this.path,
|
||||
required this.duration,
|
||||
required this.waveform,
|
||||
// #Pangea
|
||||
required this.bytes,
|
||||
// Pangea#
|
||||
});
|
||||
|
||||
factory RecordingResult.fromJson(Map<String, dynamic> json) =>
|
||||
|
|
@ -243,11 +277,17 @@ class RecordingResult {
|
|||
path: json['path'],
|
||||
duration: json['duration'],
|
||||
waveform: List<int>.from(json['waveform']),
|
||||
// #Pangea
|
||||
bytes: Uint8List.fromList(json['bytes']),
|
||||
// Pangea#
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'path': path,
|
||||
'duration': duration,
|
||||
'waveform': waveform,
|
||||
// #Pangea
|
||||
'bytes': bytes,
|
||||
// Pangea#
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import 'dart:io';
|
|||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
|
|
@ -29,7 +28,10 @@ abstract class PlatformInfos {
|
|||
|
||||
static bool get usesTouchscreen => !isMobile;
|
||||
|
||||
static bool get platformCanRecord => (isMobile || isMacOS);
|
||||
// #Pangea
|
||||
// static bool get platformCanRecord => (isMobile || isMacOS);
|
||||
static bool get platformCanRecord => (isMobile || isMacOS || kIsWeb);
|
||||
// Pangea#
|
||||
|
||||
static String get clientName =>
|
||||
'${AppConfig.applicationName} ${isWeb ? 'web' : Platform.operatingSystem}${kReleaseMode ? '' : 'Debug'}';
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue