mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 21:09:21 +00:00
Create peer connection for remote streams
This commit is contained in:
parent
473402149a
commit
45d903bcf7
@ -182,7 +182,9 @@ class WebSocketHelper {
|
|||||||
peerID: msg.data["peerID"],
|
peerID: msg.data["peerID"],
|
||||||
candidate: signalData.containsKey("candidate")
|
candidate: signalData.containsKey("candidate")
|
||||||
? RTCIceCandidate(
|
? RTCIceCandidate(
|
||||||
signalData["candidate"], null, signalData["sdpMLineIndex"])
|
signalData["candidate"],
|
||||||
|
"${signalData["sdpMLineIndex"]}" /* fix plugin crash */,
|
||||||
|
signalData["sdpMLineIndex"])
|
||||||
: null,
|
: null,
|
||||||
sessionDescription: signalData.containsKey("type")
|
sessionDescription: signalData.containsKey("type")
|
||||||
? RTCSessionDescription(signalData["sdp"], signalData["type"])
|
? RTCSessionDescription(signalData["sdp"], signalData["type"])
|
||||||
|
@ -10,4 +10,9 @@ class CallConfig {
|
|||||||
const CallConfig({
|
const CallConfig({
|
||||||
@required this.iceServers,
|
@required this.iceServers,
|
||||||
}) : assert(iceServers != null);
|
}) : assert(iceServers != null);
|
||||||
|
|
||||||
|
/// Turn this call configuration into the right for the WebRTC plugin
|
||||||
|
Map<String, dynamic> get pluginConfig => {
|
||||||
|
"iceServers": iceServers.map((f) => {"url": f}).toList()
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,8 @@ import 'package:comunic/utils/account_utils.dart';
|
|||||||
import 'package:comunic/utils/intl_utils.dart';
|
import 'package:comunic/utils/intl_utils.dart';
|
||||||
import 'package:comunic/utils/ui_utils.dart';
|
import 'package:comunic/utils/ui_utils.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_webrtc/rtc_peerconnection.dart';
|
||||||
|
import 'package:flutter_webrtc/webrtc.dart';
|
||||||
|
|
||||||
/// Call screen
|
/// Call screen
|
||||||
///
|
///
|
||||||
@ -41,6 +43,7 @@ class _CallScreenState extends SafeState<CallScreen> {
|
|||||||
var _error = false;
|
var _error = false;
|
||||||
CallMembersList _membersList;
|
CallMembersList _membersList;
|
||||||
UsersList _usersList;
|
UsersList _usersList;
|
||||||
|
final _peersConnections = Map<int, RTCPeerConnection>();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -141,6 +144,18 @@ class _CallScreenState extends SafeState<CallScreen> {
|
|||||||
_membersList.getUser(memberID).status = MemberStatus.READY;
|
_membersList.getUser(memberID).status = MemberStatus.READY;
|
||||||
setState(() {});
|
setState(() {});
|
||||||
|
|
||||||
|
// Create peer connection
|
||||||
|
final peerConnection = await createPeerConnection(_conf.pluginConfig, {
|
||||||
|
"mandatory": {
|
||||||
|
"OfferToReceiveAudio": true,
|
||||||
|
"OfferToReceiveVideo":
|
||||||
|
_conversation.callCapabilities == CallCapabilities.VIDEO,
|
||||||
|
},
|
||||||
|
"optional": [],
|
||||||
|
});
|
||||||
|
|
||||||
|
_peersConnections[memberID] = peerConnection;
|
||||||
|
|
||||||
// Request an offer to establish a peer connection
|
// Request an offer to establish a peer connection
|
||||||
await CallsHelper.requestOffer(convID, memberID);
|
await CallsHelper.requestOffer(convID, memberID);
|
||||||
} catch (e, stack) {
|
} catch (e, stack) {
|
||||||
@ -150,9 +165,38 @@ class _CallScreenState extends SafeState<CallScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Call this method each time we get a new signal
|
/// Call this method each time we get a new signal
|
||||||
void _newSignal(NewCallSignalEvent ev) {
|
void _newSignal(NewCallSignalEvent ev) async {
|
||||||
print(
|
try {
|
||||||
"${ev.peerID} - ${ev.sessionDescription != null ? ev.sessionDescription.toMap() : ev.candidate.toMap()}");
|
// Check if we can process this message
|
||||||
|
if (!_peersConnections.containsKey(ev.peerID)) {
|
||||||
|
print(
|
||||||
|
"Could not process a signal for the connection with peer ${ev.peerID}!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check the kind of signal
|
||||||
|
// SessionDescription
|
||||||
|
if (ev.sessionDescription != null) {
|
||||||
|
await _peersConnections[ev.peerID]
|
||||||
|
.setRemoteDescription(ev.sessionDescription);
|
||||||
|
|
||||||
|
// Send answer if required
|
||||||
|
if (ev.sessionDescription.type == "offer") {
|
||||||
|
final answer = await _peersConnections[ev.peerID].createAnswer({});
|
||||||
|
|
||||||
|
//TODO : Send answer back to server
|
||||||
|
print("ANSWER TO SEND ${answer.toMap()}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ice Candidate
|
||||||
|
else {
|
||||||
|
await _peersConnections[ev.peerID].addCandidate(ev.candidate);
|
||||||
|
}
|
||||||
|
} catch (e, stack) {
|
||||||
|
print("Error while handling new signal ! $e\n$stack");
|
||||||
|
showSimpleSnack(context, tr("Error while processing new signal!"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Call this when a user has interrupted streaming
|
/// Call this when a user has interrupted streaming
|
||||||
|
Loading…
Reference in New Issue
Block a user