mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-12-26 04:48:51 +00:00
Start streaming
This commit is contained in:
parent
a16618bb51
commit
b9a329c8f0
@ -62,4 +62,8 @@ class CallsHelper {
|
||||
"type": "CANDIDATE",
|
||||
"data": jsonEncode(candidate.toMap())
|
||||
});
|
||||
|
||||
/// Mark ourselves as ready to stream to other peers
|
||||
static Future<void> markPeerReady(int callID) async =>
|
||||
await ws("calls/mark_ready", {"callID": callID});
|
||||
}
|
||||
|
@ -200,6 +200,39 @@ class _CallScreenState extends SafeState<CallScreen> {
|
||||
await _renderers[userID()].initialize();
|
||||
_renderers[userID()].srcObject = _localStream;
|
||||
setState(() {});
|
||||
|
||||
// Open stream
|
||||
final peerConnection = await createPeerConnection(_conf.pluginConfig, {
|
||||
"mandatory": {},
|
||||
"optional": [],
|
||||
});
|
||||
|
||||
_peersConnections[userID()] = peerConnection;
|
||||
await peerConnection.addStream(_localStream);
|
||||
|
||||
peerConnection.onAddStream =
|
||||
(s) => throw Exception("Got a new stream on main peer connection!");
|
||||
peerConnection.onIceCandidate =
|
||||
(c) => CallsHelper.sendIceCandidate(convID, userID(), c);
|
||||
peerConnection.onIceConnectionState = (c) {
|
||||
print("New connection state: $c");
|
||||
|
||||
if (c == RTCIceConnectionState.RTCIceConnectionStateConnected)
|
||||
CallsHelper.markPeerReady(convID);
|
||||
};
|
||||
peerConnection.onSignalingState = (c) => print("New signaling state: $c");
|
||||
|
||||
// Create & send offer
|
||||
final offer = await peerConnection.createOffer({
|
||||
"mandatory": {
|
||||
"OfferToReceiveAudio": true,
|
||||
"OfferToReceiveVideo": true,
|
||||
},
|
||||
"optional": [],
|
||||
});
|
||||
await peerConnection.setLocalDescription(offer);
|
||||
|
||||
await CallsHelper.sendSessionDescription(convID, userID(), offer);
|
||||
} catch (e, stack) {
|
||||
print("Could not start streaming! $e\n$stack");
|
||||
showSimpleSnack(context, tr("Could not start streaming!"));
|
||||
@ -208,6 +241,12 @@ class _CallScreenState extends SafeState<CallScreen> {
|
||||
|
||||
/// Stop local streaming
|
||||
Future<void> _stopStreaming() async {
|
||||
// Close peer connection
|
||||
if (_peersConnections.containsKey(userID())) {
|
||||
_peersConnections[userID()].close();
|
||||
_peersConnections.remove(userID());
|
||||
}
|
||||
|
||||
// Stop local stream
|
||||
if (_localStream != null) {
|
||||
await _localStream.dispose();
|
||||
|
Loading…
Reference in New Issue
Block a user