Updates
parent
3fb8876c31
commit
a60f66a069
@ -1,204 +1,204 @@
|
|||||||
import 'dart:async';
|
// import 'dart:async';
|
||||||
import 'dart:convert';
|
// import 'dart:convert';
|
||||||
|
//
|
||||||
import 'package:diplomaticquarterapp/pages/conference/web_rtc/widgets/cam_view_widget.dart';
|
// import 'package:diplomaticquarterapp/pages/conference/web_rtc/widgets/cam_view_widget.dart';
|
||||||
import 'package:diplomaticquarterapp/pages/conference/widgets/noise_box.dart';
|
// import 'package:diplomaticquarterapp/pages/conference/widgets/noise_box.dart';
|
||||||
import 'package:diplomaticquarterapp/pages/webRTC/signaling.dart';
|
// import 'package:diplomaticquarterapp/pages/webRTC/signaling.dart';
|
||||||
import 'package:flutter/material.dart';
|
// import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
// import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_webrtc/flutter_webrtc.dart';
|
// import 'package:flutter_webrtc/flutter_webrtc.dart';
|
||||||
|
//
|
||||||
import '../conference_button_bar.dart';
|
// import '../conference_button_bar.dart';
|
||||||
|
//
|
||||||
class CallHomePage extends StatefulWidget {
|
// class CallHomePage extends StatefulWidget {
|
||||||
final String receiverId;
|
// final String receiverId;
|
||||||
final String callerId;
|
// final String callerId;
|
||||||
|
//
|
||||||
const CallHomePage({Key key, this.receiverId, this.callerId}) : super(key: key);
|
// const CallHomePage({Key key, this.receiverId, this.callerId}) : super(key: key);
|
||||||
|
//
|
||||||
@override
|
// @override
|
||||||
_CallHomePageState createState() => _CallHomePageState();
|
// _CallHomePageState createState() => _CallHomePageState();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
class _CallHomePageState extends State<CallHomePage> {
|
// class _CallHomePageState extends State<CallHomePage> {
|
||||||
bool showNoise = true;
|
// bool showNoise = true;
|
||||||
RTCVideoRenderer _localRenderer = RTCVideoRenderer();
|
// RTCVideoRenderer _localRenderer = RTCVideoRenderer();
|
||||||
RTCVideoRenderer _remoteRenderer = RTCVideoRenderer();
|
// RTCVideoRenderer _remoteRenderer = RTCVideoRenderer();
|
||||||
|
//
|
||||||
final StreamController<bool> _audioButton = StreamController<bool>.broadcast();
|
// final StreamController<bool> _audioButton = StreamController<bool>.broadcast();
|
||||||
final StreamController<bool> _videoButton = StreamController<bool>.broadcast();
|
// final StreamController<bool> _videoButton = StreamController<bool>.broadcast();
|
||||||
final StreamController<bool> _onButtonBarVisibleStreamController = StreamController<bool>.broadcast();
|
// final StreamController<bool> _onButtonBarVisibleStreamController = StreamController<bool>.broadcast();
|
||||||
final StreamController<double> _onButtonBarHeightStreamController = StreamController<double>.broadcast();
|
// final StreamController<double> _onButtonBarHeightStreamController = StreamController<double>.broadcast();
|
||||||
|
//
|
||||||
//Stream to enable video
|
// //Stream to enable video
|
||||||
MediaStream localMediaStream;
|
// MediaStream localMediaStream;
|
||||||
MediaStream remoteMediaStream;
|
// MediaStream remoteMediaStream;
|
||||||
Signaling signaling = Signaling();
|
// Signaling signaling = Signaling();
|
||||||
|
//
|
||||||
@override
|
// @override
|
||||||
void initState() {
|
// void initState() {
|
||||||
// TODO: implement initState
|
// // TODO: implement initState
|
||||||
super.initState();
|
// super.initState();
|
||||||
startCall();
|
// startCall();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
startCall() async{
|
// startCall() async{
|
||||||
await _localRenderer.initialize();
|
// await _localRenderer.initialize();
|
||||||
await _remoteRenderer.initialize();
|
// await _remoteRenderer.initialize();
|
||||||
await signaling.init();
|
// await signaling.init();
|
||||||
final connected = await receivedCall();
|
// final connected = await receivedCall();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
Future<bool> receivedCall() async {
|
// Future<bool> receivedCall() async {
|
||||||
//Stream local media
|
// //Stream local media
|
||||||
localMediaStream = await navigator.mediaDevices.getUserMedia({'video': true, 'audio': true});
|
// localMediaStream = await navigator.mediaDevices.getUserMedia({'video': true, 'audio': true});
|
||||||
_localRenderer.srcObject = localMediaStream;
|
// _localRenderer.srcObject = localMediaStream;
|
||||||
|
//
|
||||||
final connected = await signaling.acceptCall(widget.callerId, widget.receiverId, localMediaStream: localMediaStream,
|
// final connected = await signaling.acceptCall(widget.callerId, widget.receiverId, localMediaStream: localMediaStream,
|
||||||
onRemoteMediaStream: (remoteMediaStream){
|
// onRemoteMediaStream: (remoteMediaStream){
|
||||||
|
//
|
||||||
// print(remoteMediaStream.toString());
|
// // print(remoteMediaStream.toString());
|
||||||
// print(json.encode(remoteMediaStream.getTracks().asMap()));
|
// // print(json.encode(remoteMediaStream.getTracks().asMap()));
|
||||||
this.remoteMediaStream = remoteMediaStream;
|
// this.remoteMediaStream = remoteMediaStream;
|
||||||
_remoteRenderer.srcObject = remoteMediaStream;
|
// _remoteRenderer.srcObject = remoteMediaStream;
|
||||||
_remoteRenderer.addListener(() {
|
// _remoteRenderer.addListener(() {
|
||||||
print('_remoteRenderer');
|
// print('_remoteRenderer');
|
||||||
print(_remoteRenderer);
|
// print(_remoteRenderer);
|
||||||
setState(() {});
|
// setState(() {});
|
||||||
});
|
// });
|
||||||
},
|
// },
|
||||||
onRemoteTrack: (track){
|
// onRemoteTrack: (track){
|
||||||
_remoteRenderer.srcObject.addTrack(track.track);
|
// _remoteRenderer.srcObject.addTrack(track.track);
|
||||||
// setState(() {
|
// // setState(() {
|
||||||
// });
|
// // });
|
||||||
|
//
|
||||||
print(track.streams.first.getVideoTracks());
|
// print(track.streams.first.getVideoTracks());
|
||||||
print(track.streams.first.getAudioTracks());
|
// print(track.streams.first.getAudioTracks());
|
||||||
print(json.encode(track.streams.asMap()));
|
// print(json.encode(track.streams.asMap()));
|
||||||
}
|
// }
|
||||||
);
|
// );
|
||||||
|
//
|
||||||
if(connected){
|
// if(connected){
|
||||||
signaling.signalR.listen(
|
// signaling.signalR.listen(
|
||||||
onAcceptCall: (arg0){
|
// onAcceptCall: (arg0){
|
||||||
print(arg0.toString());
|
// print(arg0.toString());
|
||||||
},
|
// },
|
||||||
onCandidate: (candidateJson){
|
// onCandidate: (candidateJson){
|
||||||
signaling.addCandidate(candidateJson);
|
// signaling.addCandidate(candidateJson);
|
||||||
},
|
// },
|
||||||
onDeclineCall: (arg0,arg1){
|
// onDeclineCall: (arg0,arg1){
|
||||||
// _onHangup();
|
// // _onHangup();
|
||||||
},
|
// },
|
||||||
onHangupCall: (arg0){
|
// onHangupCall: (arg0){
|
||||||
// _onHangup();
|
// // _onHangup();
|
||||||
},
|
// },
|
||||||
|
//
|
||||||
onOffer: (offerSdp, callerUser) async{
|
// onOffer: (offerSdp, callerUser) async{
|
||||||
print('${offerSdp.toString()} | ${callerUser.toString()}');
|
// print('${offerSdp.toString()} | ${callerUser.toString()}');
|
||||||
await signaling.answerOffer(offerSdp);
|
// await signaling.answerOffer(offerSdp);
|
||||||
}
|
// }
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
return connected;
|
// return connected;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@override
|
// @override
|
||||||
void dispose() {
|
// void dispose() {
|
||||||
// TODO: implement dispose
|
// // TODO: implement dispose
|
||||||
super.dispose();
|
// super.dispose();
|
||||||
signaling.dispose();
|
// signaling.dispose();
|
||||||
_localRenderer?.dispose();
|
// _localRenderer?.dispose();
|
||||||
_remoteRenderer?.dispose();
|
// _remoteRenderer?.dispose();
|
||||||
_audioButton?.close();
|
// _audioButton?.close();
|
||||||
_videoButton?.close();
|
// _videoButton?.close();
|
||||||
localMediaStream?.dispose();
|
// localMediaStream?.dispose();
|
||||||
remoteMediaStream?.dispose();
|
// remoteMediaStream?.dispose();
|
||||||
_disposeStreamsAndSubscriptions();
|
// _disposeStreamsAndSubscriptions();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
Future<void> _disposeStreamsAndSubscriptions() async {
|
// Future<void> _disposeStreamsAndSubscriptions() async {
|
||||||
if (_onButtonBarVisibleStreamController != null) await _onButtonBarVisibleStreamController.close();
|
// if (_onButtonBarVisibleStreamController != null) await _onButtonBarVisibleStreamController.close();
|
||||||
if (_onButtonBarHeightStreamController != null) await _onButtonBarHeightStreamController.close();
|
// if (_onButtonBarHeightStreamController != null) await _onButtonBarHeightStreamController.close();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@override
|
// @override
|
||||||
Widget build(BuildContext context) {
|
// Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
// return Scaffold(
|
||||||
backgroundColor: Colors.white,
|
// backgroundColor: Colors.white,
|
||||||
body: buildLayout(),
|
// body: buildLayout(),
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
LayoutBuilder buildLayout() {
|
// LayoutBuilder buildLayout() {
|
||||||
return LayoutBuilder(
|
// return LayoutBuilder(
|
||||||
builder: (BuildContext context, BoxConstraints constraints) {
|
// builder: (BuildContext context, BoxConstraints constraints) {
|
||||||
return Stack(
|
// return Stack(
|
||||||
children: [
|
// children: [
|
||||||
CamViewWidget(
|
// CamViewWidget(
|
||||||
localRenderer: _localRenderer,
|
// localRenderer: _localRenderer,
|
||||||
remoteRenderer: _remoteRenderer,
|
// remoteRenderer: _remoteRenderer,
|
||||||
constraints: constraints,
|
// constraints: constraints,
|
||||||
onButtonBarVisibleStreamController: _onButtonBarVisibleStreamController,
|
// onButtonBarVisibleStreamController: _onButtonBarVisibleStreamController,
|
||||||
onButtonBarHeightStreamController: _onButtonBarHeightStreamController,
|
// onButtonBarHeightStreamController: _onButtonBarHeightStreamController,
|
||||||
),
|
// ),
|
||||||
ConferenceButtonBar(
|
// ConferenceButtonBar(
|
||||||
audioEnabled: _audioButton.stream,
|
// audioEnabled: _audioButton.stream,
|
||||||
videoEnabled: _videoButton.stream,
|
// videoEnabled: _videoButton.stream,
|
||||||
onAudioEnabled: _onAudioEnable,
|
// onAudioEnabled: _onAudioEnable,
|
||||||
onVideoEnabled: _onVideoEnabled,
|
// onVideoEnabled: _onVideoEnabled,
|
||||||
onSwitchCamera: _onSwitchCamera,
|
// onSwitchCamera: _onSwitchCamera,
|
||||||
onHangup: _onHangup,
|
// onHangup: _onHangup,
|
||||||
onPersonAdd: () {},
|
// onPersonAdd: () {},
|
||||||
onPersonRemove: () {},
|
// onPersonRemove: () {},
|
||||||
onHeight: _onHeightBar,
|
// onHeight: _onHeightBar,
|
||||||
onShow: _onShowBar,
|
// onShow: _onShowBar,
|
||||||
onHide: _onHideBar,
|
// onHide: _onHideBar,
|
||||||
),
|
// ),
|
||||||
],
|
// ],
|
||||||
);
|
// );
|
||||||
},
|
// },
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
Function _onAudioEnable() {
|
// Function _onAudioEnable() {
|
||||||
final audioTrack = localMediaStream.getAudioTracks()[0];
|
// final audioTrack = localMediaStream.getAudioTracks()[0];
|
||||||
final mute = audioTrack.muted;
|
// final mute = audioTrack.muted;
|
||||||
Helper.setMicrophoneMute(!mute, audioTrack);
|
// Helper.setMicrophoneMute(!mute, audioTrack);
|
||||||
_audioButton.add(mute);
|
// _audioButton.add(mute);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
Function _onVideoEnabled() {
|
// Function _onVideoEnabled() {
|
||||||
final videoTrack = localMediaStream.getVideoTracks()[0];
|
// final videoTrack = localMediaStream.getVideoTracks()[0];
|
||||||
bool videoEnabled = videoTrack.enabled;
|
// bool videoEnabled = videoTrack.enabled;
|
||||||
localMediaStream.getVideoTracks()[0].enabled = !videoEnabled;
|
// localMediaStream.getVideoTracks()[0].enabled = !videoEnabled;
|
||||||
_videoButton.add(!videoEnabled);
|
// _videoButton.add(!videoEnabled);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
Function _onSwitchCamera() {
|
// Function _onSwitchCamera() {
|
||||||
Helper.switchCamera(localMediaStream.getVideoTracks()[0]);
|
// Helper.switchCamera(localMediaStream.getVideoTracks()[0]);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
void _onShowBar() {
|
// void _onShowBar() {
|
||||||
setState(() {
|
// setState(() {
|
||||||
});
|
// });
|
||||||
_onButtonBarVisibleStreamController.add(true);
|
// _onButtonBarVisibleStreamController.add(true);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
void _onHeightBar(double height) {
|
// void _onHeightBar(double height) {
|
||||||
_onButtonBarHeightStreamController.add(height);
|
// _onButtonBarHeightStreamController.add(height);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
void _onHideBar() {
|
// void _onHideBar() {
|
||||||
setState(() {
|
// setState(() {
|
||||||
SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom]);
|
// SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom]);
|
||||||
});
|
// });
|
||||||
_onButtonBarVisibleStreamController.add(false);
|
// _onButtonBarVisibleStreamController.add(false);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
Future<void> _onHangup() async {
|
// Future<void> _onHangup() async {
|
||||||
signaling.hangupCall(widget.callerId, widget.receiverId);
|
// signaling.hangupCall(widget.callerId, widget.receiverId);
|
||||||
print('onHangup');
|
// print('onHangup');
|
||||||
Navigator.of(context).pop();
|
// Navigator.of(context).pop();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|||||||
@ -1,164 +1,164 @@
|
|||||||
import 'dart:io';
|
// import 'dart:io';
|
||||||
|
//
|
||||||
import 'package:diplomaticquarterapp/models/LiveCare/IncomingCallData.dart';
|
// import 'package:diplomaticquarterapp/models/LiveCare/IncomingCallData.dart';
|
||||||
import 'package:diplomaticquarterapp/pages/livecare/incoming_call.dart';
|
// import 'package:diplomaticquarterapp/pages/livecare/incoming_call.dart';
|
||||||
import 'package:diplomaticquarterapp/pages/webRTC/signaling.dart';
|
// import 'package:diplomaticquarterapp/pages/webRTC/signaling.dart';
|
||||||
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
|
// import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
|
||||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
// import 'package:firebase_messaging/firebase_messaging.dart';
|
||||||
import 'package:flutter/material.dart';
|
// import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_webrtc/flutter_webrtc.dart';
|
// import 'package:flutter_webrtc/flutter_webrtc.dart';
|
||||||
|
//
|
||||||
class CallPage extends StatefulWidget {
|
// class CallPage extends StatefulWidget {
|
||||||
@override
|
// @override
|
||||||
_CallPageState createState() => _CallPageState();
|
// _CallPageState createState() => _CallPageState();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
class _CallPageState extends State<CallPage> {
|
// class _CallPageState extends State<CallPage> {
|
||||||
Signaling signaling = Signaling();
|
// Signaling signaling = Signaling();
|
||||||
RTCVideoRenderer _localRenderer = RTCVideoRenderer();
|
// RTCVideoRenderer _localRenderer = RTCVideoRenderer();
|
||||||
RTCVideoRenderer _remoteRenderer = RTCVideoRenderer();
|
// RTCVideoRenderer _remoteRenderer = RTCVideoRenderer();
|
||||||
String roomId;
|
// String roomId;
|
||||||
TextEditingController textEditingController = TextEditingController(text: '');
|
// TextEditingController textEditingController = TextEditingController(text: '');
|
||||||
|
//
|
||||||
@override
|
// @override
|
||||||
void initState() {
|
// void initState() {
|
||||||
_localRenderer.initialize();
|
// _localRenderer.initialize();
|
||||||
_remoteRenderer.initialize();
|
// _remoteRenderer.initialize();
|
||||||
|
//
|
||||||
// signaling.onRemoteStream = ((stream) {
|
// // signaling.onRemoteStream = ((stream) {
|
||||||
// _remoteRenderer.srcObject = stream;
|
// // _remoteRenderer.srcObject = stream;
|
||||||
// setState(() {});
|
// // setState(() {});
|
||||||
// });
|
// // });
|
||||||
|
//
|
||||||
fcmConfigure();
|
// fcmConfigure();
|
||||||
|
//
|
||||||
super.initState();
|
// super.initState();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@override
|
// @override
|
||||||
void dispose() {
|
// void dispose() {
|
||||||
_localRenderer.dispose();
|
// _localRenderer.dispose();
|
||||||
_remoteRenderer.dispose();
|
// _remoteRenderer.dispose();
|
||||||
super.dispose();
|
// super.dispose();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@override
|
// @override
|
||||||
Widget build(BuildContext context) {
|
// Widget build(BuildContext context) {
|
||||||
FirebaseMessaging.instance.getToken().then((value) {
|
// FirebaseMessaging.instance.getToken().then((value) {
|
||||||
print('FCM_TOKEN: $value');
|
// print('FCM_TOKEN: $value');
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
return AppScaffold(
|
// return AppScaffold(
|
||||||
isShowAppBar: true,
|
// isShowAppBar: true,
|
||||||
showNewAppBar: true,
|
// showNewAppBar: true,
|
||||||
showNewAppBarTitle: true,
|
// showNewAppBarTitle: true,
|
||||||
isShowDecPage: false,
|
// isShowDecPage: false,
|
||||||
appBarTitle: "WebRTC Calling",
|
// appBarTitle: "WebRTC Calling",
|
||||||
body: Column(
|
// body: Column(
|
||||||
children: [
|
// children: [
|
||||||
SizedBox(height: 8),
|
// SizedBox(height: 8),
|
||||||
Wrap(
|
// Wrap(
|
||||||
children: [
|
// children: [
|
||||||
SizedBox(
|
// SizedBox(
|
||||||
width: 8,
|
// width: 8,
|
||||||
),
|
// ),
|
||||||
ElevatedButton(
|
// ElevatedButton(
|
||||||
onPressed: () {
|
// onPressed: () {
|
||||||
dummyCall();
|
// dummyCall();
|
||||||
},
|
// },
|
||||||
child: Text("Call"),
|
// child: Text("Call"),
|
||||||
),
|
// ),
|
||||||
SizedBox(
|
// SizedBox(
|
||||||
width: 8,
|
// width: 8,
|
||||||
),
|
// ),
|
||||||
ElevatedButton(
|
// ElevatedButton(
|
||||||
onPressed: () {
|
// onPressed: () {
|
||||||
signaling.hangUp(_localRenderer);
|
// signaling.hangUp(_localRenderer);
|
||||||
},
|
// },
|
||||||
child: Text("Hangup"),
|
// child: Text("Hangup"),
|
||||||
)
|
// )
|
||||||
],
|
// ],
|
||||||
),
|
// ),
|
||||||
SizedBox(height: 8),
|
// SizedBox(height: 8),
|
||||||
Expanded(
|
// Expanded(
|
||||||
child: Padding(
|
// child: Padding(
|
||||||
padding: const EdgeInsets.all(0.0),
|
// padding: const EdgeInsets.all(0.0),
|
||||||
child: Stack(
|
// child: Stack(
|
||||||
children: [
|
// children: [
|
||||||
Positioned(top: 0.0, right: 0.0, left: 0.0, bottom: 0.0, child: RTCVideoView(_remoteRenderer)),
|
// Positioned(top: 0.0, right: 0.0, left: 0.0, bottom: 0.0, child: RTCVideoView(_remoteRenderer)),
|
||||||
Positioned(
|
// Positioned(
|
||||||
top: 20.0,
|
// top: 20.0,
|
||||||
right: 100.0,
|
// right: 100.0,
|
||||||
left: 20.0,
|
// left: 20.0,
|
||||||
bottom: 300.0,
|
// bottom: 300.0,
|
||||||
child: RTCVideoView(_localRenderer, mirror: true),
|
// child: RTCVideoView(_localRenderer, mirror: true),
|
||||||
),
|
// ),
|
||||||
],
|
// ],
|
||||||
),
|
// ),
|
||||||
),
|
// ),
|
||||||
),
|
// ),
|
||||||
Padding(
|
// Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
// padding: const EdgeInsets.all(8.0),
|
||||||
child: Row(
|
// child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
// mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
// children: [
|
||||||
Text("Join the following Room: "),
|
// Text("Join the following Room: "),
|
||||||
Flexible(
|
// Flexible(
|
||||||
child: TextFormField(
|
// child: TextFormField(
|
||||||
controller: textEditingController,
|
// controller: textEditingController,
|
||||||
),
|
// ),
|
||||||
)
|
// )
|
||||||
],
|
// ],
|
||||||
),
|
// ),
|
||||||
),
|
// ),
|
||||||
SizedBox(height: 8)
|
// SizedBox(height: 8)
|
||||||
],
|
// ],
|
||||||
),
|
// ),
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
dummyCall() async {
|
// dummyCall() async {
|
||||||
final json = {
|
// final json = {
|
||||||
"callerID": "9920",
|
// "callerID": "9920",
|
||||||
"receiverID": "2001273",
|
// "receiverID": "2001273",
|
||||||
"msgID": "123",
|
// "msgID": "123",
|
||||||
"notfID": "123",
|
// "notfID": "123",
|
||||||
"notification_foreground": "true",
|
// "notification_foreground": "true",
|
||||||
"count": "1",
|
// "count": "1",
|
||||||
"message": "Doctor is calling ",
|
// "message": "Doctor is calling ",
|
||||||
"AppointmentNo": "123",
|
// "AppointmentNo": "123",
|
||||||
"title": "Rayyan Hospital",
|
// "title": "Rayyan Hospital",
|
||||||
"ProjectID": "123",
|
// "ProjectID": "123",
|
||||||
"NotificationType": "10",
|
// "NotificationType": "10",
|
||||||
"background": "1",
|
// "background": "1",
|
||||||
"doctorname": "Dr Sulaiman Al Habib",
|
// "doctorname": "Dr Sulaiman Al Habib",
|
||||||
"clinicname": "ENT Clinic",
|
// "clinicname": "ENT Clinic",
|
||||||
"speciality": "Speciality",
|
// "speciality": "Speciality",
|
||||||
"appointmentdate": "Sun, 15th Dec, 2019",
|
// "appointmentdate": "Sun, 15th Dec, 2019",
|
||||||
"appointmenttime": "09:00",
|
// "appointmenttime": "09:00",
|
||||||
"type": "video",
|
// "type": "video",
|
||||||
"session_id":
|
// "session_id":
|
||||||
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImN0eSI6InR3aWxpby1mcGE7dj0xIn0.eyJqdGkiOiJTS2I2NjYyOWMzN2ZhOTM3YjFjNDI2Zjg1MTgyNWFmN2M0LTE1OTg3NzQ1MDYiLCJpc3MiOiJTS2I2NjYyOWMzN2ZhOTM3YjFjNDI2Zjg1MTgyNWFmN2M0Iiwic3ViIjoiQUNhYWQ1YTNmOGM2NGZhNjczNTY3NTYxNTc0N2YyNmMyYiIsImV4cCI6MTU5ODc3ODEwNiwiZ3JhbnRzIjp7ImlkZW50aXR5IjoiSGFyb29uMSIsInZpZGVvIjp7InJvb20iOiJTbWFsbERhaWx5U3RhbmR1cCJ9fX0.7XUS5uMQQJfkrBZu9EjQ6STL6R7iXkso6BtO1HmrQKk",
|
// "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImN0eSI6InR3aWxpby1mcGE7dj0xIn0.eyJqdGkiOiJTS2I2NjYyOWMzN2ZhOTM3YjFjNDI2Zjg1MTgyNWFmN2M0LTE1OTg3NzQ1MDYiLCJpc3MiOiJTS2I2NjYyOWMzN2ZhOTM3YjFjNDI2Zjg1MTgyNWFmN2M0Iiwic3ViIjoiQUNhYWQ1YTNmOGM2NGZhNjczNTY3NTYxNTc0N2YyNmMyYiIsImV4cCI6MTU5ODc3ODEwNiwiZ3JhbnRzIjp7ImlkZW50aXR5IjoiSGFyb29uMSIsInZpZGVvIjp7InJvb20iOiJTbWFsbERhaWx5U3RhbmR1cCJ9fX0.7XUS5uMQQJfkrBZu9EjQ6STL6R7iXkso6BtO1HmrQKk",
|
||||||
"identity": "Haroon1",
|
// "identity": "Haroon1",
|
||||||
"name": "SmallDailyStandup",
|
// "name": "SmallDailyStandup",
|
||||||
"videoUrl": "video",
|
// "videoUrl": "video",
|
||||||
"picture": "video",
|
// "picture": "video",
|
||||||
"is_call": "true"
|
// "is_call": "true"
|
||||||
};
|
// };
|
||||||
|
//
|
||||||
IncomingCallData incomingCallData = IncomingCallData.fromJson(json);
|
// IncomingCallData incomingCallData = IncomingCallData.fromJson(json);
|
||||||
final result = await Navigator.push(context, MaterialPageRoute(builder: (context) => IncomingCall(incomingCallData: incomingCallData)));
|
// final result = await Navigator.push(context, MaterialPageRoute(builder: (context) => IncomingCall(incomingCallData: incomingCallData)));
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
fcmConfigure() {
|
// fcmConfigure() {
|
||||||
FirebaseMessaging.onMessage.listen((RemoteMessage message) async {
|
// FirebaseMessaging.onMessage.listen((RemoteMessage message) async {
|
||||||
print(message.toString());
|
// print(message.toString());
|
||||||
|
//
|
||||||
IncomingCallData incomingCallData;
|
// IncomingCallData incomingCallData;
|
||||||
if (Platform.isAndroid)
|
// if (Platform.isAndroid)
|
||||||
incomingCallData = IncomingCallData.fromJson(message.data['data']);
|
// incomingCallData = IncomingCallData.fromJson(message.data['data']);
|
||||||
else if (Platform.isIOS) incomingCallData = IncomingCallData.fromJson(message.data);
|
// else if (Platform.isIOS) incomingCallData = IncomingCallData.fromJson(message.data);
|
||||||
if (incomingCallData != null) final result = await Navigator.push(context, MaterialPageRoute(builder: (context) => IncomingCall(incomingCallData: incomingCallData)));
|
// if (incomingCallData != null) final result = await Navigator.push(context, MaterialPageRoute(builder: (context) => IncomingCall(incomingCallData: incomingCallData)));
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|||||||
@ -1,277 +1,277 @@
|
|||||||
import 'dart:convert';
|
// import 'dart:convert';
|
||||||
|
//
|
||||||
import 'package:diplomaticquarterapp/uitl/SignalRUtil.dart';
|
// import 'package:diplomaticquarterapp/uitl/SignalRUtil.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
// import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter_webrtc/flutter_webrtc.dart';
|
// import 'package:flutter_webrtc/flutter_webrtc.dart';
|
||||||
|
//
|
||||||
typedef void StreamStateCallback(MediaStream stream);
|
// typedef void StreamStateCallback(MediaStream stream);
|
||||||
typedef void RTCIceGatheringStateCallback(RTCIceGatheringState state);
|
// typedef void RTCIceGatheringStateCallback(RTCIceGatheringState state);
|
||||||
typedef void RTCPeerConnectionStateCallback(RTCPeerConnectionState state);
|
// typedef void RTCPeerConnectionStateCallback(RTCPeerConnectionState state);
|
||||||
typedef void RTCSignalingStateCallback(RTCSignalingState state);
|
// typedef void RTCSignalingStateCallback(RTCSignalingState state);
|
||||||
|
//
|
||||||
final Map<String, dynamic> constraints = {
|
// final Map<String, dynamic> constraints = {
|
||||||
'mandatory': {},
|
// 'mandatory': {},
|
||||||
'optional': [
|
// 'optional': [
|
||||||
{'DtlsSrtpKeyAgreement': true},
|
// {'DtlsSrtpKeyAgreement': true},
|
||||||
]
|
// ]
|
||||||
};
|
// };
|
||||||
|
//
|
||||||
Map<String, dynamic> snapsis_ice_config = {
|
// Map<String, dynamic> snapsis_ice_config = {
|
||||||
'iceServers': [
|
// 'iceServers': [
|
||||||
{ "urls": 'stun:15.185.116.59:3478' },
|
// { "urls": 'stun:15.185.116.59:3478' },
|
||||||
{ "urls": "turn:15.185.116.59:3479", "username": "admin", "credential": "admin" },
|
// { "urls": "turn:15.185.116.59:3479", "username": "admin", "credential": "admin" },
|
||||||
],
|
// ],
|
||||||
// 'sdpSemantics': 'unified-plan'
|
// // 'sdpSemantics': 'unified-plan'
|
||||||
};
|
// };
|
||||||
Map<String, dynamic> twilio_ice_config = {
|
// Map<String, dynamic> twilio_ice_config = {
|
||||||
"ice_servers": [
|
// "ice_servers": [
|
||||||
{
|
// {
|
||||||
"url": "stun:global.stun.twilio.com:3478?transport=udp",
|
// "url": "stun:global.stun.twilio.com:3478?transport=udp",
|
||||||
"urls": "stun:global.stun.twilio.com:3478?transport=udp"
|
// "urls": "stun:global.stun.twilio.com:3478?transport=udp"
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
"url": "turn:global.turn.twilio.com:3478?transport=udp",
|
// "url": "turn:global.turn.twilio.com:3478?transport=udp",
|
||||||
"username": "ce8042842b62c21bd20b176f80d6067fd3db81b1e9766312418ef5421d9ca2a2",
|
// "username": "ce8042842b62c21bd20b176f80d6067fd3db81b1e9766312418ef5421d9ca2a2",
|
||||||
"urls": "turn:global.turn.twilio.com:3478?transport=udp",
|
// "urls": "turn:global.turn.twilio.com:3478?transport=udp",
|
||||||
"credential": "UzGOsiLwPZJ32cjafAebfDDpVrqeQjgpFHZEdau/8r4="
|
// "credential": "UzGOsiLwPZJ32cjafAebfDDpVrqeQjgpFHZEdau/8r4="
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
"url": "turn:global.turn.twilio.com:3478?transport=tcp",
|
// "url": "turn:global.turn.twilio.com:3478?transport=tcp",
|
||||||
"username": "ce8042842b62c21bd20b176f80d6067fd3db81b1e9766312418ef5421d9ca2a2",
|
// "username": "ce8042842b62c21bd20b176f80d6067fd3db81b1e9766312418ef5421d9ca2a2",
|
||||||
"urls": "turn:global.turn.twilio.com:3478?transport=tcp",
|
// "urls": "turn:global.turn.twilio.com:3478?transport=tcp",
|
||||||
"credential": "UzGOsiLwPZJ32cjafAebfDDpVrqeQjgpFHZEdau/8r4="
|
// "credential": "UzGOsiLwPZJ32cjafAebfDDpVrqeQjgpFHZEdau/8r4="
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
"url": "turn:global.turn.twilio.com:443?transport=tcp",
|
// "url": "turn:global.turn.twilio.com:443?transport=tcp",
|
||||||
"username": "ce8042842b62c21bd20b176f80d6067fd3db81b1e9766312418ef5421d9ca2a2",
|
// "username": "ce8042842b62c21bd20b176f80d6067fd3db81b1e9766312418ef5421d9ca2a2",
|
||||||
"urls": "turn:global.turn.twilio.com:443?transport=tcp",
|
// "urls": "turn:global.turn.twilio.com:443?transport=tcp",
|
||||||
"credential": "UzGOsiLwPZJ32cjafAebfDDpVrqeQjgpFHZEdau/8r4="
|
// "credential": "UzGOsiLwPZJ32cjafAebfDDpVrqeQjgpFHZEdau/8r4="
|
||||||
}
|
// }
|
||||||
],
|
// ],
|
||||||
// 'sdpSemantics': 'unified-plan'
|
// // 'sdpSemantics': 'unified-plan'
|
||||||
};
|
// };
|
||||||
Map<String, dynamic> google_ice_config = {
|
// Map<String, dynamic> google_ice_config = {
|
||||||
'iceServers': [
|
// 'iceServers': [
|
||||||
{
|
// {
|
||||||
'urls': [
|
// 'urls': [
|
||||||
'stun:stun.l.google.com:19302',
|
// 'stun:stun.l.google.com:19302',
|
||||||
'stun:stun1.l.google.com:19302',
|
// 'stun:stun1.l.google.com:19302',
|
||||||
'stun:stun2.l.google.com:19302',
|
// 'stun:stun2.l.google.com:19302',
|
||||||
'stun:stun3.l.google.com:19302'
|
// 'stun:stun3.l.google.com:19302'
|
||||||
]
|
// ]
|
||||||
},
|
// },
|
||||||
],
|
// ],
|
||||||
// 'sdpSemantics': 'unified-plan'
|
// // 'sdpSemantics': 'unified-plan'
|
||||||
};
|
// };
|
||||||
Map<String, dynamic> aws_ice_config = {
|
// Map<String, dynamic> aws_ice_config = {
|
||||||
'iceServers': [
|
// 'iceServers': [
|
||||||
{'url': "stun:ec2-15-185-116-59.me-south-1.compute.amazonaws.com:3478"},
|
// {'url': "stun:ec2-15-185-116-59.me-south-1.compute.amazonaws.com:3478"},
|
||||||
{'url': "turn:ec2-15-185-116-59.me-south-1.compute.amazonaws.com:3479", 'credential': "admin", 'username': "admin"}
|
// {'url': "turn:ec2-15-185-116-59.me-south-1.compute.amazonaws.com:3479", 'credential': "admin", 'username': "admin"}
|
||||||
],
|
// ],
|
||||||
// 'sdpSemantics': 'unified-plan'
|
// // 'sdpSemantics': 'unified-plan'
|
||||||
};
|
// };
|
||||||
|
//
|
||||||
class Signaling {
|
// class Signaling {
|
||||||
dispose() {
|
// dispose() {
|
||||||
if (peerConnection != null) {
|
// if (peerConnection != null) {
|
||||||
peerConnection.dispose();
|
// peerConnection.dispose();
|
||||||
peerConnection.getLocalStreams().forEach((e) => e.dispose());
|
// peerConnection.getLocalStreams().forEach((e) => e.dispose());
|
||||||
peerConnection.getRemoteStreams().forEach((e) => e.dispose());
|
// peerConnection.getRemoteStreams().forEach((e) => e.dispose());
|
||||||
}
|
// }
|
||||||
signalR.closeConnection();
|
// signalR.closeConnection();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
init() async{
|
// init() async{
|
||||||
// Create Peer Connection
|
// // Create Peer Connection
|
||||||
peerConnection = await createPeerConnection(google_ice_config, constraints);
|
// peerConnection = await createPeerConnection(google_ice_config, constraints);
|
||||||
registerPeerConnectionListeners();
|
// registerPeerConnectionListeners();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
initializeSignalR(String userName) async {
|
// initializeSignalR(String userName) async {
|
||||||
if (signalR != null) await signalR.closeConnection();
|
// if (signalR != null) await signalR.closeConnection();
|
||||||
// https://vcallapi.hmg.com/webRTCHub?source=web&username=zohaib
|
// // https://vcallapi.hmg.com/webRTCHub?source=web&username=zohaib
|
||||||
// signalR = SignalRUtil(hubName: "https://vcallapi.hmg.com/webRTCHub?source=mobile&username=$userName");
|
// // signalR = SignalRUtil(hubName: "https://vcallapi.hmg.com/webRTCHub?source=mobile&username=$userName");
|
||||||
signalR = SignalRUtil(hubName: "http://35.193.237.29/webRTCHub?source=mobile&username=$userName");
|
// signalR = SignalRUtil(hubName: "http://35.193.237.29/webRTCHub?source=mobile&username=$userName");
|
||||||
final connected = await signalR.openConnection();
|
// final connected = await signalR.openConnection();
|
||||||
if (!connected) throw 'Failed to connect SignalR';
|
// if (!connected) throw 'Failed to connect SignalR';
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
Map<String, dynamic> configuration = {
|
// Map<String, dynamic> configuration = {
|
||||||
// 'iceServers': [
|
// // 'iceServers': [
|
||||||
// {
|
// // {
|
||||||
// 'urls': ['stun:stun1.l.google.com:19302', 'stun:stun2.l.google.com:19302']
|
// // 'urls': ['stun:stun1.l.google.com:19302', 'stun:stun2.l.google.com:19302']
|
||||||
// }
|
// // }
|
||||||
// ]
|
// // ]
|
||||||
|
//
|
||||||
'iceServers': [
|
// 'iceServers': [
|
||||||
// {'url': "stun:ec2-15-185-116-59.me-south-1.compute.amazonaws.com:3478"},
|
// // {'url': "stun:ec2-15-185-116-59.me-south-1.compute.amazonaws.com:3478"},
|
||||||
// {'url': "turn:ec2-15-185-116-59.me-south-1.compute.amazonaws.com:3479", 'credential': "admin", 'username': "admin"}
|
// // {'url': "turn:ec2-15-185-116-59.me-south-1.compute.amazonaws.com:3479", 'credential': "admin", 'username': "admin"}
|
||||||
// {'url': "stun:15.185.116.59:3478"},
|
// // {'url': "stun:15.185.116.59:3478"},
|
||||||
// {
|
// // {
|
||||||
// "url":"turn:15.185.116.59:3479",
|
// // "url":"turn:15.185.116.59:3479",
|
||||||
// "username": "admin",
|
// // "username": "admin",
|
||||||
// "credential":"admin"
|
// // "credential":"admin"
|
||||||
// }
|
// // }
|
||||||
{
|
// {
|
||||||
"url": "stun:global.stun.twilio.com:3478?transport=udp",
|
// "url": "stun:global.stun.twilio.com:3478?transport=udp",
|
||||||
"urls": "stun:global.stun.twilio.com:3478?transport=udp"
|
// "urls": "stun:global.stun.twilio.com:3478?transport=udp"
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
"url": "turn:global.turn.twilio.com:3478?transport=udp",
|
// "url": "turn:global.turn.twilio.com:3478?transport=udp",
|
||||||
"username": "f18fc347ba4aeeaa1b00f5199b1e900834b464962d434a4a89b4cdba02510047",
|
// "username": "f18fc347ba4aeeaa1b00f5199b1e900834b464962d434a4a89b4cdba02510047",
|
||||||
"urls": "turn:global.turn.twilio.com:3478?transport=udp",
|
// "urls": "turn:global.turn.twilio.com:3478?transport=udp",
|
||||||
"credential": "WX16BB+9nKm0f+Whf5EwpM8S/Yv+T2tlvQWLfdV7oqo="
|
// "credential": "WX16BB+9nKm0f+Whf5EwpM8S/Yv+T2tlvQWLfdV7oqo="
|
||||||
}
|
// }
|
||||||
]
|
// ]
|
||||||
};
|
// };
|
||||||
|
//
|
||||||
SignalRUtil signalR;
|
// SignalRUtil signalR;
|
||||||
|
//
|
||||||
RTCPeerConnection peerConnection;
|
// RTCPeerConnection peerConnection;
|
||||||
MediaStream localStream;
|
// MediaStream localStream;
|
||||||
MediaStream remoteStream;
|
// MediaStream remoteStream;
|
||||||
RTCDataChannel dataChannel;
|
// RTCDataChannel dataChannel;
|
||||||
|
//
|
||||||
// Future<bool> call(String patientId, String mobile, {@required RTCVideoRenderer localVideo, @required RTCVideoRenderer remoteVideo}) async {
|
// // Future<bool> call(String patientId, String mobile, {@required RTCVideoRenderer localVideo, @required RTCVideoRenderer remoteVideo}) async {
|
||||||
// await initializeSignalR(patientId);
|
// // await initializeSignalR(patientId);
|
||||||
//
|
// //
|
||||||
// // final isCallPlaced = await FCM.sendCallNotifcationTo(DOCTOR_TOKEN, patientId, mobile);
|
// // // final isCallPlaced = await FCM.sendCallNotifcationTo(DOCTOR_TOKEN, patientId, mobile);
|
||||||
// if(!isCallPlaced)
|
// // if(!isCallPlaced)
|
||||||
// throw 'Failed to notify target for call';
|
// // throw 'Failed to notify target for call';
|
||||||
//
|
// //
|
||||||
// return isCallPlaced;
|
// // return isCallPlaced;
|
||||||
// }
|
// // }
|
||||||
|
//
|
||||||
Future<bool> acceptCall(String caller, String receiver, {@required MediaStream localMediaStream, @required Function(MediaStream) onRemoteMediaStream, @required Function(RTCTrackEvent) onRemoteTrack}) async {
|
// Future<bool> acceptCall(String caller, String receiver, {@required MediaStream localMediaStream, @required Function(MediaStream) onRemoteMediaStream, @required Function(RTCTrackEvent) onRemoteTrack}) async {
|
||||||
await initializeSignalR(receiver);
|
// await initializeSignalR(receiver);
|
||||||
signalR.setContributors(caller: caller, receiver: receiver);
|
// signalR.setContributors(caller: caller, receiver: receiver);
|
||||||
await signalR.acceptCall(receiver, caller).catchError((e) => throw 'Failed to inform signalR that i accepted a call');
|
// await signalR.acceptCall(receiver, caller).catchError((e) => throw 'Failed to inform signalR that i accepted a call');
|
||||||
|
//
|
||||||
peerConnection.addStream(localMediaStream);
|
// peerConnection.addStream(localMediaStream);
|
||||||
|
//
|
||||||
// peerConnection?.onTrack = (track){
|
// // peerConnection?.onTrack = (track){
|
||||||
// onRemoteTrack(track);
|
// // onRemoteTrack(track);
|
||||||
// };
|
// // };
|
||||||
peerConnection?.onAddStream = (MediaStream stream) {
|
// peerConnection?.onAddStream = (MediaStream stream) {
|
||||||
remoteStream = stream;
|
// remoteStream = stream;
|
||||||
onRemoteMediaStream?.call(stream);
|
// onRemoteMediaStream?.call(stream);
|
||||||
};
|
// };
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
Future<bool> declineCall(String caller, String receiver) async {
|
// Future<bool> declineCall(String caller, String receiver) async {
|
||||||
await initializeSignalR(receiver);
|
// await initializeSignalR(receiver);
|
||||||
signalR.setContributors(caller: caller, receiver: receiver);
|
// signalR.setContributors(caller: caller, receiver: receiver);
|
||||||
await signalR.declineCall(receiver, caller).catchError((e) => throw 'Failed to inform signalR that i accepted a call');
|
// await signalR.declineCall(receiver, caller).catchError((e) => throw 'Failed to inform signalR that i accepted a call');
|
||||||
|
//
|
||||||
// peerConnection.addStream(localMediaStream);
|
// // peerConnection.addStream(localMediaStream);
|
||||||
//
|
// //
|
||||||
// peerConnection?.onAddStream = (MediaStream stream) {
|
// // peerConnection?.onAddStream = (MediaStream stream) {
|
||||||
// remoteStream = stream;
|
// // remoteStream = stream;
|
||||||
// onRemoteMediaStream?.call(stream);
|
// // onRemoteMediaStream?.call(stream);
|
||||||
// };
|
// // };
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
Future hangupCall(String caller, String receiver) async {
|
// Future hangupCall(String caller, String receiver) async {
|
||||||
await signalR.hangupCall(caller, receiver);
|
// await signalR.hangupCall(caller, receiver);
|
||||||
dispose();
|
// dispose();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
answerOffer(String sdp) async {
|
// answerOffer(String sdp) async {
|
||||||
final offer = jsonDecode(sdp);
|
// final offer = jsonDecode(sdp);
|
||||||
final caller = offer['caller'];
|
// final caller = offer['caller'];
|
||||||
final receiver = offer['target'];
|
// final receiver = offer['target'];
|
||||||
final offerSdp = offer['sdp'];
|
// final offerSdp = offer['sdp'];
|
||||||
peerConnection.setRemoteDescription(rtcSessionDescriptionFrom(offerSdp)).then((value) {
|
// peerConnection.setRemoteDescription(rtcSessionDescriptionFrom(offerSdp)).then((value) {
|
||||||
return peerConnection.createAnswer().catchError((e){
|
// return peerConnection.createAnswer().catchError((e){
|
||||||
print(e);
|
// print(e);
|
||||||
});
|
// });
|
||||||
}).then((anwser) {
|
// }).then((anwser) {
|
||||||
return peerConnection.setLocalDescription(anwser).catchError((e){
|
// return peerConnection.setLocalDescription(anwser).catchError((e){
|
||||||
print(e);
|
// print(e);
|
||||||
});
|
// });
|
||||||
}).then((value) {
|
// }).then((value) {
|
||||||
return peerConnection.getLocalDescription().catchError((e){
|
// return peerConnection.getLocalDescription().catchError((e){
|
||||||
print(e);
|
// print(e);
|
||||||
});
|
// });
|
||||||
}).then((answer) {
|
// }).then((answer) {
|
||||||
return signalR.answerOffer(answer, caller, receiver).catchError((e){
|
// return signalR.answerOffer(answer, caller, receiver).catchError((e){
|
||||||
print(e);
|
// print(e);
|
||||||
});
|
// });
|
||||||
}).catchError((e) {
|
// }).catchError((e) {
|
||||||
print(e);
|
// print(e);
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
Future<void> hangUp(RTCVideoRenderer localVideo) async {}
|
// Future<void> hangUp(RTCVideoRenderer localVideo) async {}
|
||||||
|
//
|
||||||
Future<String> createSdpAnswer(String toOfferSdp) async {
|
// Future<String> createSdpAnswer(String toOfferSdp) async {
|
||||||
final offerSdp = rtcSessionDescriptionFrom(jsonDecode(toOfferSdp));
|
// final offerSdp = rtcSessionDescriptionFrom(jsonDecode(toOfferSdp));
|
||||||
peerConnection.setRemoteDescription(offerSdp).catchError((e){
|
// peerConnection.setRemoteDescription(offerSdp).catchError((e){
|
||||||
print(e);
|
// print(e);
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
final answer = await peerConnection.createAnswer().catchError((e){
|
// final answer = await peerConnection.createAnswer().catchError((e){
|
||||||
print(e);
|
// print(e);
|
||||||
});
|
// });
|
||||||
var answerSdp = json.encode(answer); // Send SDP via Push or any channel
|
// var answerSdp = json.encode(answer); // Send SDP via Push or any channel
|
||||||
return answerSdp;
|
// return answerSdp;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
Future<String> createSdpOffer() async {
|
// Future<String> createSdpOffer() async {
|
||||||
final offer = await peerConnection.createOffer();
|
// final offer = await peerConnection.createOffer();
|
||||||
await peerConnection.setLocalDescription(offer).catchError((e){
|
// await peerConnection.setLocalDescription(offer).catchError((e){
|
||||||
print(e);
|
// print(e);
|
||||||
});
|
// });
|
||||||
final map = offer.toMap();
|
// final map = offer.toMap();
|
||||||
var offerSdp = json.encode(map); // Send SDP via Push or any channel
|
// var offerSdp = json.encode(map); // Send SDP via Push or any channel
|
||||||
return offerSdp;
|
// return offerSdp;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
addCandidate(String candidateJson) {
|
// addCandidate(String candidateJson) {
|
||||||
peerConnection.addCandidate(rtcIceCandidateFrom(candidateJson)).catchError((e){
|
// peerConnection.addCandidate(rtcIceCandidateFrom(candidateJson)).catchError((e){
|
||||||
print(e);
|
// print(e);
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
void registerPeerConnectionListeners() {
|
// void registerPeerConnectionListeners() {
|
||||||
peerConnection.onRenegotiationNeeded = (){
|
// peerConnection.onRenegotiationNeeded = (){
|
||||||
print('Renegotiation Needed...');
|
// print('Renegotiation Needed...');
|
||||||
};
|
// };
|
||||||
|
//
|
||||||
peerConnection.onIceCandidate = (RTCIceCandidate candidate) {
|
// peerConnection.onIceCandidate = (RTCIceCandidate candidate) {
|
||||||
// print(json.encode(candidate.toMap()));
|
// // print(json.encode(candidate.toMap()));
|
||||||
signalR.addIceCandidate(json.encode(candidate.toMap())).catchError((e){
|
// signalR.addIceCandidate(json.encode(candidate.toMap())).catchError((e){
|
||||||
print(e);
|
// print(e);
|
||||||
});
|
// });
|
||||||
};
|
// };
|
||||||
|
//
|
||||||
peerConnection?.onIceGatheringState = (RTCIceGatheringState state) {
|
// peerConnection?.onIceGatheringState = (RTCIceGatheringState state) {
|
||||||
print('ICE gathering state changed: $state');
|
// print('ICE gathering state changed: $state');
|
||||||
};
|
// };
|
||||||
|
//
|
||||||
peerConnection?.onConnectionState = (RTCPeerConnectionState state) {
|
// peerConnection?.onConnectionState = (RTCPeerConnectionState state) {
|
||||||
print('Connection state change: $state');
|
// print('Connection state change: $state');
|
||||||
};
|
// };
|
||||||
|
//
|
||||||
peerConnection?.onSignalingState = (RTCSignalingState state) {
|
// peerConnection?.onSignalingState = (RTCSignalingState state) {
|
||||||
print('Signaling state change: $state');
|
// print('Signaling state change: $state');
|
||||||
};
|
// };
|
||||||
|
//
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
rtcSessionDescriptionFrom(Map sdp) {
|
// rtcSessionDescriptionFrom(Map sdp) {
|
||||||
return RTCSessionDescription(
|
// return RTCSessionDescription(
|
||||||
sdp['sdp'],
|
// sdp['sdp'],
|
||||||
sdp['type'],
|
// sdp['type'],
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
rtcIceCandidateFrom(String json) {
|
// rtcIceCandidateFrom(String json) {
|
||||||
final map = jsonDecode(json)['candidate'];
|
// final map = jsonDecode(json)['candidate'];
|
||||||
return RTCIceCandidate(map['candidate'], map['sdpMid'], map['sdpMLineIndex']);
|
// return RTCIceCandidate(map['candidate'], map['sdpMid'], map['sdpMLineIndex']);
|
||||||
}
|
// }
|
||||||
|
|||||||
@ -1,173 +1,173 @@
|
|||||||
import 'dart:convert';
|
// import 'dart:convert';
|
||||||
import 'dart:io';
|
// import 'dart:io';
|
||||||
|
//
|
||||||
import 'package:flutter/cupertino.dart';
|
// import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter_webrtc/flutter_webrtc.dart';
|
// import 'package:flutter_webrtc/flutter_webrtc.dart';
|
||||||
import 'package:http/io_client.dart';
|
// import 'package:http/io_client.dart';
|
||||||
import 'package:signalr_core/signalr_core.dart';
|
// import 'package:signalr_core/signalr_core.dart';
|
||||||
|
//
|
||||||
class SignalRUtil {
|
// class SignalRUtil {
|
||||||
String hubName;
|
// String hubName;
|
||||||
|
//
|
||||||
String sourceUser;
|
// String sourceUser;
|
||||||
String destinationUser;
|
// String destinationUser;
|
||||||
setContributors({@required String caller, @required String receiver}){
|
// setContributors({@required String caller, @required String receiver}){
|
||||||
this.sourceUser = caller;
|
// this.sourceUser = caller;
|
||||||
this.destinationUser = receiver;
|
// this.destinationUser = receiver;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
Function(bool) onConnected;
|
// Function(bool) onConnected;
|
||||||
SignalRUtil({@required this.hubName});
|
// SignalRUtil({@required this.hubName});
|
||||||
|
//
|
||||||
|
//
|
||||||
HubConnection connectionHub;
|
// HubConnection connectionHub;
|
||||||
|
//
|
||||||
closeConnection() async{
|
// closeConnection() async{
|
||||||
if(connectionHub != null) {
|
// if(connectionHub != null) {
|
||||||
connectionHub.off('OnIncomingCallAsync');
|
// connectionHub.off('OnIncomingCallAsync');
|
||||||
connectionHub.off('OnCallDeclinedAsync');
|
// connectionHub.off('OnCallDeclinedAsync');
|
||||||
connectionHub.off('OnCallAcceptedAsync');
|
// connectionHub.off('OnCallAcceptedAsync');
|
||||||
connectionHub.off('nHangUpAsync');
|
// connectionHub.off('nHangUpAsync');
|
||||||
connectionHub.off('OnIceCandidateAsync');
|
// connectionHub.off('OnIceCandidateAsync');
|
||||||
connectionHub.off('OnOfferAsync');
|
// connectionHub.off('OnOfferAsync');
|
||||||
await connectionHub.stop();
|
// await connectionHub.stop();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
Future<bool> openConnection() async {
|
// Future<bool> openConnection() async {
|
||||||
connectionHub = HubConnectionBuilder()
|
// connectionHub = HubConnectionBuilder()
|
||||||
.withUrl(
|
// .withUrl(
|
||||||
hubName,
|
// hubName,
|
||||||
HttpConnectionOptions(
|
// HttpConnectionOptions(
|
||||||
logMessageContent: true,
|
// logMessageContent: true,
|
||||||
client: IOClient(HttpClient()..badCertificateCallback = (x, y, z) => true),
|
// client: IOClient(HttpClient()..badCertificateCallback = (x, y, z) => true),
|
||||||
logging: (level, message) => print(message),
|
// logging: (level, message) => print(message),
|
||||||
)).build();
|
// )).build();
|
||||||
|
//
|
||||||
await connectionHub.start();
|
// await connectionHub.start();
|
||||||
await Future.delayed(Duration(seconds: 1));
|
// await Future.delayed(Duration(seconds: 1));
|
||||||
|
//
|
||||||
connectionHub.on('ReceiveMessage', (message) {
|
// connectionHub.on('ReceiveMessage', (message) {
|
||||||
handleIncomingMessage(message);
|
// handleIncomingMessage(message);
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
return getConnectionState();
|
// return getConnectionState();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
void handleIncomingMessage(List<dynamic> message) {
|
// void handleIncomingMessage(List<dynamic> message) {
|
||||||
print(message.toString());
|
// print(message.toString());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
void sendMessage(List<dynamic> args) async {
|
// void sendMessage(List<dynamic> args) async {
|
||||||
await connectionHub.invoke('SendMessage', args: args); //['Bob', 'Says hi!']
|
// await connectionHub.invoke('SendMessage', args: args); //['Bob', 'Says hi!']
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
listen({Function(CallUser) onAcceptCall, Function(CallUser) onHangupCall, Function(String, CallUser) onDeclineCall, Function(String, CallUser) onOffer, Function(String) onCandidate}){
|
// listen({Function(CallUser) onAcceptCall, Function(CallUser) onHangupCall, Function(String, CallUser) onDeclineCall, Function(String, CallUser) onOffer, Function(String) onCandidate}){
|
||||||
|
//
|
||||||
connectionHub.on('OnIncomingCallAsync', (arguments) {
|
// connectionHub.on('OnIncomingCallAsync', (arguments) {
|
||||||
print('OnIncomingCallAsync: ${arguments.toString()}');
|
// print('OnIncomingCallAsync: ${arguments.toString()}');
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
connectionHub.on('OnCallDeclinedAsync', (arguments) {
|
// connectionHub.on('OnCallDeclinedAsync', (arguments) {
|
||||||
print('OnCallDeclinedAsync: ${arguments.toString()}');
|
// print('OnCallDeclinedAsync: ${arguments.toString()}');
|
||||||
onDeclineCall(arguments.first, CallUser.from(arguments.last));
|
// onDeclineCall(arguments.first, CallUser.from(arguments.last));
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
connectionHub.on('OnCallAcceptedAsync', (arguments) {
|
// connectionHub.on('OnCallAcceptedAsync', (arguments) {
|
||||||
print('OnCallAcceptedAsync: ${arguments.toString()}');
|
// print('OnCallAcceptedAsync: ${arguments.toString()}');
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
connectionHub.on('OnHangUpAsync', (arguments) {
|
// connectionHub.on('OnHangUpAsync', (arguments) {
|
||||||
print('nHangUpAsync: ${arguments.toString()}');
|
// print('nHangUpAsync: ${arguments.toString()}');
|
||||||
onHangupCall(CallUser.from(arguments.first));
|
// onHangupCall(CallUser.from(arguments.first));
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
connectionHub.on('OnIceCandidateAsync', (arguments) {
|
// connectionHub.on('OnIceCandidateAsync', (arguments) {
|
||||||
print('OnIceCandidateAsync: ${arguments.toString()}');
|
// print('OnIceCandidateAsync: ${arguments.toString()}');
|
||||||
onCandidate(arguments.first);
|
// onCandidate(arguments.first);
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
connectionHub.on('OnOfferAsync', (arguments) {
|
// connectionHub.on('OnOfferAsync', (arguments) {
|
||||||
print('OnOfferAsync: ${arguments.toString()}');
|
// print('OnOfferAsync: ${arguments.toString()}');
|
||||||
onOffer(arguments.first, CallUser.from(arguments.last));
|
// onOffer(arguments.first, CallUser.from(arguments.last));
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// CallUserAsync(string currentUserId, string targerUserId)
|
// // CallUserAsync(string currentUserId, string targerUserId)
|
||||||
Future<dynamic> callUser(String from, to) async{
|
// Future<dynamic> callUser(String from, to) async{
|
||||||
return await connectionHub.invoke('CallUserAsync', args: [from, to]);
|
// return await connectionHub.invoke('CallUserAsync', args: [from, to]);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// CallDeclinedAsync(string currentUserId, string targerUserId)
|
// // CallDeclinedAsync(string currentUserId, string targerUserId)
|
||||||
Future<dynamic> declineCall(String from, to) async{
|
// Future<dynamic> declineCall(String from, to) async{
|
||||||
return await connectionHub.invoke('CallDeclinedAsync', args: [from, to]);
|
// return await connectionHub.invoke('CallDeclinedAsync', args: [from, to]);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// AnswerCallAsync(string currentUserId, string targetUserId)
|
// // AnswerCallAsync(string currentUserId, string targetUserId)
|
||||||
Future<dynamic> answerCall(String from, to) async{
|
// Future<dynamic> answerCall(String from, to) async{
|
||||||
return await connectionHub.invoke('AnswerCallAsync', args: [from, to]);
|
// return await connectionHub.invoke('AnswerCallAsync', args: [from, to]);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// IceCandidateAsync(string targetUserId, string candidate)
|
// // IceCandidateAsync(string targetUserId, string candidate)
|
||||||
Future<dynamic> addIceCandidate(String candidate) async{
|
// Future<dynamic> addIceCandidate(String candidate) async{
|
||||||
final target = destinationUser;
|
// final target = destinationUser;
|
||||||
return await connectionHub.invoke('IceCandidateAsync', args: [target, candidate]);
|
// return await connectionHub.invoke('IceCandidateAsync', args: [target, candidate]);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// OfferAsync(string targetUserId,string currentUserId, string targetOffer)
|
// // OfferAsync(string targetUserId,string currentUserId, string targetOffer)
|
||||||
Future<dynamic> offer(String from, to, offer) async{
|
// Future<dynamic> offer(String from, to, offer) async{
|
||||||
return await connectionHub.invoke('OfferAsync', args: [from, to, offer]);
|
// return await connectionHub.invoke('OfferAsync', args: [from, to, offer]);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// AnswerOfferAsync(string targetUserId, string CallerOffer)
|
// // AnswerOfferAsync(string targetUserId, string CallerOffer)
|
||||||
Future<dynamic> answerOffer(RTCSessionDescription answerSdp, caller, receiver) async{
|
// Future<dynamic> answerOffer(RTCSessionDescription answerSdp, caller, receiver) async{
|
||||||
final payload = {
|
// final payload = {
|
||||||
'target': receiver,
|
// 'target': receiver,
|
||||||
'caller': caller,
|
// 'caller': caller,
|
||||||
'sdp': answerSdp.toMap(),
|
// 'sdp': answerSdp.toMap(),
|
||||||
};
|
// };
|
||||||
return await connectionHub.invoke('AnswerOfferAsync', args: [caller, jsonEncode(payload)]);
|
// return await connectionHub.invoke('AnswerOfferAsync', args: [caller, jsonEncode(payload)]);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// HangUpAsync(string currentUserId, string targetUserId)
|
// // HangUpAsync(string currentUserId, string targetUserId)
|
||||||
Future<dynamic> hangupCall(String from, to) async{
|
// Future<dynamic> hangupCall(String from, to) async{
|
||||||
return await connectionHub.invoke('HangUpAsync', args: [from, to]);
|
// return await connectionHub.invoke('HangUpAsync', args: [from, to]);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// CallAccepted(string currentUserId,string targetUserId)
|
// // CallAccepted(string currentUserId,string targetUserId)
|
||||||
Future<dynamic> acceptCall(String from, to) async{
|
// Future<dynamic> acceptCall(String from, to) async{
|
||||||
// return await connectionHub.send(methodName: 'CallAccepted', args: [from, to]);
|
// // return await connectionHub.send(methodName: 'CallAccepted', args: [from, to]);
|
||||||
return await connectionHub.invoke("CallAccepted", args: [ from, to]);
|
// return await connectionHub.invoke("CallAccepted", args: [ from, to]);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
bool getConnectionState() {
|
// bool getConnectionState() {
|
||||||
if (connectionHub.state == HubConnectionState.connected) return true;
|
// if (connectionHub.state == HubConnectionState.connected) return true;
|
||||||
if (connectionHub.state == HubConnectionState.disconnected) return false;
|
// if (connectionHub.state == HubConnectionState.disconnected) return false;
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
class CallUser{
|
// class CallUser{
|
||||||
String Id;
|
// String Id;
|
||||||
String UserName;
|
// String UserName;
|
||||||
String Email;
|
// String Email;
|
||||||
String Phone;
|
// String Phone;
|
||||||
String Title;
|
// String Title;
|
||||||
dynamic UserStatus;
|
// dynamic UserStatus;
|
||||||
String Image;
|
// String Image;
|
||||||
int UnreadMessageCount = 0;
|
// int UnreadMessageCount = 0;
|
||||||
|
//
|
||||||
CallUser.from(Map map){
|
// CallUser.from(Map map){
|
||||||
Id = map['Id'];
|
// Id = map['Id'];
|
||||||
UserName = map['UserName'];
|
// UserName = map['UserName'];
|
||||||
Email = map['Email'];
|
// Email = map['Email'];
|
||||||
Phone = map['Phone'];
|
// Phone = map['Phone'];
|
||||||
Title = map['Title'];
|
// Title = map['Title'];
|
||||||
UserStatus = map['UserStatus'];
|
// UserStatus = map['UserStatus'];
|
||||||
Image = map['Image'];
|
// Image = map['Image'];
|
||||||
UnreadMessageCount = map['UnreadMessageCount'];
|
// UnreadMessageCount = map['UnreadMessageCount'];
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
Loading…
Reference in New Issue