You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
235 lines
8.4 KiB
Dart
235 lines
8.4 KiB
Dart
//
|
|
// import 'dart:async';
|
|
// import 'dart:collection';
|
|
// import 'dart:html' as html;
|
|
// import 'dart:io';
|
|
// import 'dart:js' as js;
|
|
// import 'dart:typed_data';
|
|
// import 'package:diplomaticquarterapp/pages/videocall-webrtc-rnd/js_wrapper/multistreammixer-wrapper.dart';
|
|
// import 'package:diplomaticquarterapp/pages/videocall-webrtc-rnd/utils/blob-extension.dart';
|
|
// import 'package:diplomaticquarterapp/pages/videocall-webrtc-rnd/utils/upload-recording.dart';
|
|
// import 'package:flutter/cupertino.dart';
|
|
// import 'package:flutter_webrtc/flutter_webrtc.dart';
|
|
//
|
|
// final _recorder_options = {
|
|
// 'mimeType': 'video/webm;codecs=vp9,opus',
|
|
// 'bitsPerSecond': 128000,
|
|
// 'audioBitsPerSecond': 128000,// only for audio track
|
|
// 'videoBitsPerSecond': 128000// only for video track
|
|
// };
|
|
//
|
|
// class WebRtcStreamRecorder{
|
|
// html.MediaStream remoteStreamWeb;
|
|
// html.MediaStream localStreamWeb;
|
|
//
|
|
// html.MediaRecorder _local_recorder;
|
|
// html.MediaRecorder _mixed_recorder;
|
|
// html.MediaRecorder _remote_recorder;
|
|
// Duration chunkDuration;
|
|
//
|
|
// WebRtcStreamRecorder({@required MediaStream remoteStream, @required MediaStream localStream}){
|
|
// remoteStreamWeb = (remoteStream as dynamic).jsStream; // MediaStreamWeb.jsStream
|
|
// localStreamWeb = (localStream as dynamic).jsStream; // MediaStreamWeb.jsStream
|
|
// }
|
|
//
|
|
// Function(html.Blob blob, bool isLast, html.MediaRecorder recorder) _blobChunkCallback;
|
|
//
|
|
// onBlobChunk(Duration chunkDuration,{@required Function(html.Blob blob, bool isLast, html.MediaRecorder recorder) onBlobChunk}){
|
|
// _blobChunkCallback = onBlobChunk;
|
|
// this.chunkDuration = chunkDuration;
|
|
// }
|
|
//
|
|
// stop(){
|
|
// _mixed_recorder?.stop();
|
|
// _remote_recorder?.stop();
|
|
// _local_recorder?.stop();
|
|
// _sliceTimer?.cancel();
|
|
// }
|
|
//
|
|
// WebRtcStreamRecorder start({bool withMixedStream = true}){
|
|
// if(withMixedStream){
|
|
// _recordMixedStream();
|
|
//
|
|
// }else{
|
|
// Future.wait<html.Blob>([_startLocal(), _startRemote()]).then((value) async{
|
|
// final localVideoData = await value[0].readBytes();
|
|
// final remoteVideoData = await value[1].readBytes();
|
|
//
|
|
// processAndSendClip(localVideoData, 'local-video');
|
|
// processAndSendClip(remoteVideoData, 'remote-video');
|
|
// print("\n\n\n");
|
|
// print("------------------------------------------------------------------------------------------------------------------------");
|
|
// print("Recordings Completed");
|
|
// print("------------------------------------------------------------------------------------------------------------------------");
|
|
// print(" Local: ${localVideoData == null ? 'not recorded' : 'recorded'}");
|
|
// print("Remote: ${remoteVideoData == null ? 'not recorded' : 'recorded'}");
|
|
// print("------------------------------------------------------------------------------------------------------------------------");
|
|
// print("\n\n\n");
|
|
//
|
|
// });
|
|
// }
|
|
// return this;
|
|
// }
|
|
//
|
|
// _recordMixedStream(){
|
|
// final mixer = initMultiStreamsMixer([remoteStreamWeb,localStreamWeb]);
|
|
// final jsMixedStream = mixer.getMixedStream();
|
|
// _mixed_recorder = html.MediaRecorder(jsMixedStream, _recorder_options);
|
|
// _startRecording(_mixed_recorder).then((blob) async {
|
|
// final data = await blob?.readBytes();
|
|
// // final url = await blob?.readDataUrl();
|
|
// final params = {
|
|
// 'requesterId':'1',
|
|
// 'source':'ziktest4',
|
|
// 'target':'adeltest4',
|
|
// 'callStart':'2022-04-13 09:00',
|
|
// 'callEnd':'2022-04-13 10:00',
|
|
// 'archive':'1'
|
|
// };
|
|
//
|
|
// print("Uploading called");
|
|
// UploadRecording().upload(blob, params: params, completion: (response){
|
|
// print("Response: $response");
|
|
// }, onProgress: (progress){
|
|
// print("Upload: ${progress.toInt()}/100");
|
|
// });
|
|
//
|
|
// // String file = await FileSaver.instance.saveFile("recorded", data!, "webm", mimeType: MimeType.WEBM).catchError((e){
|
|
// // print(e);
|
|
// // });
|
|
// // print(file);
|
|
// });
|
|
// }
|
|
//
|
|
// Future<html.Blob> _startRemote() async{
|
|
// _remote_recorder = html.MediaRecorder(remoteStreamWeb, _recorder_options);
|
|
// return _startRecording(_remote_recorder);
|
|
// }
|
|
//
|
|
// Future<html.Blob> _startLocal() async{
|
|
// _local_recorder = html.MediaRecorder(localStreamWeb, _recorder_options);
|
|
// return _startRecording(_local_recorder);
|
|
// }
|
|
//
|
|
// processAndSendClip(Uint8List data, String filename) async{
|
|
// if(data != null){
|
|
// // String file = await FileSaver.instance.saveFile("$filename", data, "webm", mimeType: MimeType.OTHER).catchError((e){
|
|
// // print(e);
|
|
// // });
|
|
// // print(file);
|
|
// }else{
|
|
//
|
|
// }
|
|
// }
|
|
// }
|
|
//
|
|
// Timer _sliceTimer;
|
|
// extension xWebRtcStreamRecorder on WebRtcStreamRecorder{
|
|
//
|
|
// @override
|
|
// Future<html.Blob> _startRecording(html.MediaRecorder recorder) async{
|
|
// html.Blob _blob;
|
|
// bool isLast = false;
|
|
// if(recorder != null){
|
|
// final completer = Completer();
|
|
// recorder.addEventListener('dataavailable', (html.Event event) async{
|
|
// _blob = js.JsObject.fromBrowserObject(event)['data'];
|
|
// isLast = recorder.state == 'inactive';
|
|
// final data = await _blob?.readBytes();
|
|
// print("dataavailable isLast:$isLast data:${data?.length}");
|
|
// if(_blobChunkCallback != null)
|
|
// _blobChunkCallback(_blob, isLast, recorder);
|
|
//
|
|
// if(isLast)
|
|
// completer.complete();
|
|
// });
|
|
// recorder.start();
|
|
// print("_startRecording Start");
|
|
// _enableSliceChunks(recorder);
|
|
//
|
|
// await completer.future;
|
|
// }
|
|
//
|
|
// print("_startRecording Finish");
|
|
// return _blob;
|
|
// }
|
|
//
|
|
// _enableSliceChunks(html.MediaRecorder recorder){
|
|
// if(chunkDuration != null && recorder != null){
|
|
// _sliceTimer = Timer.periodic(chunkDuration, (timer) {
|
|
// if(recorder.stream?.active == true){
|
|
// recorder.requestData();
|
|
// }else{
|
|
// timer.cancel();
|
|
// }
|
|
// });
|
|
// }
|
|
// }
|
|
// }
|
|
//
|
|
// // class WebRecorder {
|
|
// // static bool isNotRecording = true;
|
|
// // static html.MediaRecorder? recorder;
|
|
// //
|
|
// // final Future Function() whenRecorderStart; // Function to call when recording starts
|
|
// // final Future Function() whenRecorderStop; // Function to call when recording finishs
|
|
// // final Future Function(dynamic) whenReceiveData;
|
|
// //
|
|
// // WebRecorder({
|
|
// // required this.whenRecorderStart,
|
|
// // required this.whenRecorderStop,
|
|
// // required this.whenReceiveData
|
|
// // });
|
|
// //
|
|
// // WebRecorder openRecorder({MediaStream? stream}){
|
|
// // WebRecorder.isNotRecording = !WebRecorder.isNotRecording;
|
|
// // if(WebRecorder.isNotRecording)
|
|
// // stopRecoring().whenComplete(whenRecorderStop);
|
|
// // else
|
|
// // if(stream == null){
|
|
// // html.window.navigator
|
|
// // .getUserMedia(audio: true)
|
|
// // .then((stream) {
|
|
// // recorder = html.MediaRecorder(stream);
|
|
// // recorder?.addEventListener('dataavailable', hundlerFunctionStream);
|
|
// // })
|
|
// // .whenComplete((){
|
|
// // startRecording().whenComplete(whenRecorderStart);
|
|
// // })
|
|
// // .catchError((e)=> print);
|
|
// // }else{
|
|
// // final htmlStream = html.MediaStream(stream.getTracks());
|
|
// // recorder = html.MediaRecorder(htmlStream);
|
|
// // recorder?.addEventListener('dataavailable', hundlerFunctionStream);
|
|
// // }
|
|
// //
|
|
// // return this;
|
|
// // }
|
|
// //
|
|
// // Future<void> startRecording(){
|
|
// // WebRecorder.recorder?.start();
|
|
// // return Future.value(true);
|
|
// // }
|
|
// //
|
|
// // Future<void> stopRecoring() async{
|
|
// // WebRecorder.recorder?.stop();
|
|
// // return Future.value(true);
|
|
// // }
|
|
// //
|
|
// // hundlerFunctionStream(event) async{
|
|
// // html.FileReader reader = html.FileReader();
|
|
// // html.Blob blob = js.JsObject.fromBrowserObject(event)['data'];
|
|
// // reader.readAsArrayBuffer(blob);
|
|
// // reader.onLoadEnd.listen((e) async {
|
|
// // setData(reader.result);
|
|
// // });
|
|
// // }
|
|
// //
|
|
// // setData(data) => whenReceiveData(data);
|
|
// //
|
|
// // dispose(){
|
|
// // WebRecorder.recorder?.removeEventListener('dataavailable', hundlerFunctionStream);
|
|
// // WebRecorder.recorder = null;
|
|
// // }
|
|
// // }
|