4
2
Fork 0

added event bus for bottom bar

pull/31/head
Sudharshan S. 2019-02-17 20:57:50 +08:00
parent b4a4b6e322
commit ab514d71f3
Signed by: sudharshan
GPG Key ID: C861C97AAF3D9559
5 changed files with 30 additions and 4 deletions

View File

@ -1,5 +1,5 @@
// Overall sensible settings for development
final String baseUrlCore = "http://localhost:10200";
final String baseUrlSignalling = "http://localhost:10201";
final String baseUrlSignaling = "http://localhost:10201";
final String globalUserId = "u-3d19fb283ddb14fb5c15191438b5b69a";

View File

@ -0,0 +1,15 @@
import "package:rxdart/rxdart.dart";
class BottomBarBus {
final _bottomBarBus = PublishSubject<Map<String, dynamic>>();
Observable<Map<String, dynamic>> get bus => _bottomBarBus.stream;
publish(Map<String, dynamic> message) async {
_bottomBarBus.sink.add(message);
}
dispose() {
_bottomBarBus.close();
}
}

View File

@ -3,6 +3,7 @@ import "dart:convert";
import "package:eventsource/eventsource.dart";
import "package:flutter_webrtc/webrtc.dart";
import "package:http/http.dart" as http;
import "../../settings.dart";
// Available utility enums
enum SignalingResponse { SUCCESSFULL, NO_DEVICE, NO_DATA }
@ -51,7 +52,7 @@ class PeerConnectionFactory {
// attaches a callback to it
_initialize() async {
_signalingServer = await EventSource.connect(
"localhost:10201/subscribe/$_localUserId/device/$_localDeviceId");
"$baseUrlSignaling/subscribe/$_localUserId/device/$_localDeviceId");
_signalingServer.listen((event) {
print(event.data);
onMessageCallback(jsonDecode(event.data));

View File

@ -3,6 +3,7 @@ import "package:http/http.dart" as http;
import "dart:convert";
import "dart:async";
import "peer_connection_factory.dart";
import "../../settings.dart";
class PeerManager {
String _selfUserId;
@ -30,8 +31,7 @@ class PeerManager {
}
addPeer(String userId) async {
var response =
await http.get("http://localhost:10201/user/$userId/devices");
var response = await http.get("$baseUrlSignaling/user/$userId/devices");
List<dynamic> deviceIds = jsonDecode(response.body);
deviceIds.forEach((deviceId) async {
@ -76,6 +76,12 @@ class PeerManager {
RTCPeerConnection connection =
await _peerConnectionFactory.newPeerConnection(userId, deviceId);
// Handle streams being added and removed remotely
connection.onAddStream = (stream) => _currentStreams.add(stream);
connection.onRemoveStream =
(stream) => _currentStreams.removeWhere((it) => stream.id == it.id);
_currentConnections["$userId-$deviceId"] = connection;
connection.setRemoteDescription(

View File

@ -1,7 +1,11 @@
import "package:flutter/material.dart";
import "../../services/peer_manager.dart";
import "../../../settings.dart";
class BottomBar extends StatelessWidget {
final double barHeight = 80.0;
final _peerManager = PeerManager(globalUserId, "1");
@override
Widget build(BuildContext context) {