|
|
|
|
@ -251,19 +251,20 @@ class Signaling {
|
|
|
|
|
Future<void> connect() async {
|
|
|
|
|
|
|
|
|
|
if(connectToSignalR){
|
|
|
|
|
final hub = "https://VCallApi.hmg.com/WebRTCHub?source=web&username=s1";
|
|
|
|
|
final hub = "https://VCallApi.hmg.com/WebRTCHub?source=web&username=zik";
|
|
|
|
|
signalrUtil = SignalRUtil(hubName: hub);
|
|
|
|
|
signalrUtil.setContributors(caller: "zik", receiver: "s1");
|
|
|
|
|
|
|
|
|
|
final connected = await signalrUtil.openConnection();
|
|
|
|
|
if(connected){
|
|
|
|
|
signalrUtil.callUser("zik", "s1");
|
|
|
|
|
signalrUtil.listen(
|
|
|
|
|
onIncomingCall: (user) async{
|
|
|
|
|
await Future.delayed(Duration(seconds: 1));
|
|
|
|
|
signalrUtil.acceptCall("s1", "zik");
|
|
|
|
|
signalrUtil.acceptCall("zik", "s1");
|
|
|
|
|
},
|
|
|
|
|
onAcceptCall: (user){
|
|
|
|
|
print(user.toString());
|
|
|
|
|
_initPeerConnection(session, media: "video", screenSharing: false);
|
|
|
|
|
},
|
|
|
|
|
onDeclineCall: (str, user){
|
|
|
|
|
print(str);
|
|
|
|
|
@ -300,6 +301,17 @@ class Signaling {
|
|
|
|
|
await session.pc?.setRemoteDescription(RTCSessionDescription(offerSdp['sdp'], offerSdp['type']));
|
|
|
|
|
await _createAnswer(session, "video");
|
|
|
|
|
|
|
|
|
|
if (session.remoteCandidates.isNotEmpty) {
|
|
|
|
|
session.remoteCandidates.forEach((candidate) async {
|
|
|
|
|
await session.pc?.addCandidate(candidate);
|
|
|
|
|
});
|
|
|
|
|
session.remoteCandidates.clear();
|
|
|
|
|
}
|
|
|
|
|
onCallStateChange?.call(session, CallState.Calling);
|
|
|
|
|
},
|
|
|
|
|
onAnswer: (answer_str) async{
|
|
|
|
|
final answer = jsonDecode(answer_str);
|
|
|
|
|
await session.pc?.setRemoteDescription(RTCSessionDescription(answer['sdp'], answer['type']));
|
|
|
|
|
if (session.remoteCandidates.isNotEmpty) {
|
|
|
|
|
session.remoteCandidates.forEach((candidate) async {
|
|
|
|
|
await session.pc?.addCandidate(candidate);
|
|
|
|
|
@ -390,6 +402,7 @@ class Signaling {
|
|
|
|
|
..._iceServers,
|
|
|
|
|
...{'sdpSemantics': sdpSemantics}
|
|
|
|
|
}, _config);
|
|
|
|
|
|
|
|
|
|
if (media != 'data') {
|
|
|
|
|
switch (sdpSemantics) {
|
|
|
|
|
case 'plan-b':
|
|
|
|
|
@ -456,6 +469,11 @@ class Signaling {
|
|
|
|
|
sender.setParameters(parameters);
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pc.onRenegotiationNeeded = (){
|
|
|
|
|
offer("video", false);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pc.onIceCandidate = (candidate) async {
|
|
|
|
|
if (candidate == null) {
|
|
|
|
|
print('onIceCandidate: complete!');
|
|
|
|
|
@ -526,9 +544,16 @@ class Signaling {
|
|
|
|
|
|
|
|
|
|
Future<void> _createOffer(SessionOneToOne session, String media) async {
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
RTCSessionDescription s =
|
|
|
|
|
await session.pc .createOffer(media == 'data' ? _dcConstraints : {});
|
|
|
|
|
await session.pc.createOffer(media == 'data' ? _dcConstraints : {});
|
|
|
|
|
await session.pc .setLocalDescription(s);
|
|
|
|
|
|
|
|
|
|
if(connectToSignalR){
|
|
|
|
|
final offer = jsonEncode(s.toMap());
|
|
|
|
|
signalrUtil.offer(signalrUtil.sourceUser, signalrUtil.destinationUser, offer);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_send('offer', {
|
|
|
|
|
'to': session.remote_user?.id,
|
|
|
|
|
'from': session.local_user.id,
|
|
|
|
|
|