return connection error message, removed mediastream during publishing
This commit is contained in:
@@ -102,6 +102,20 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.6.5"
|
||||
http:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: http
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.13.3"
|
||||
http_parser:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: http_parser
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "4.0.0"
|
||||
livekit_client:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@@ -179,6 +193,13 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.1"
|
||||
pedantic:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: pedantic
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.11.1"
|
||||
platform:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
@@ -13,7 +13,6 @@ import 'participant.dart';
|
||||
|
||||
class LocalParticipant extends Participant {
|
||||
RTCEngine _engine;
|
||||
MediaStream? _mediaStream;
|
||||
|
||||
LocalParticipant({
|
||||
required RTCEngine engine,
|
||||
@@ -25,15 +24,6 @@ class LocalParticipant extends Participant {
|
||||
|
||||
RTCEngine get engine => _engine;
|
||||
|
||||
Future<MediaStream> getMediaStream() async {
|
||||
var stream = _mediaStream;
|
||||
if (stream == null) {
|
||||
stream = await createLocalMediaStream(sid);
|
||||
_mediaStream = stream;
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
||||
/// publish an audio track to the room
|
||||
Future<TrackPublication> publishAudioTrack(LocalAudioTrack track) async {
|
||||
if (audioTracks.values.any(
|
||||
@@ -44,10 +34,8 @@ class LocalParticipant extends Participant {
|
||||
try {
|
||||
var trackInfo = await _engine.addTrack(
|
||||
cid: track.getCid(), name: track.name, kind: track.kind);
|
||||
var stream = await getMediaStream();
|
||||
var transceiverInit = new RTCRtpTransceiverInit(
|
||||
direction: TransceiverDirection.SendOnly,
|
||||
streams: [stream],
|
||||
);
|
||||
track.transceiver = await _engine.publisher?.pc.addTransceiver(
|
||||
track: track.mediaTrack,
|
||||
@@ -67,7 +55,7 @@ class LocalParticipant extends Participant {
|
||||
|
||||
/// publish a video track to the room
|
||||
Future<TrackPublication> publishVideoTrack(LocalVideoTrack track) async {
|
||||
if (audioTracks.values.any(
|
||||
if (videoTracks.values.any(
|
||||
(element) => element.track?.mediaTrack.id == track.mediaTrack.id)) {
|
||||
return Future.error(TrackPublishError('track already exists'));
|
||||
}
|
||||
@@ -75,10 +63,8 @@ class LocalParticipant extends Participant {
|
||||
try {
|
||||
var trackInfo = await _engine.addTrack(
|
||||
cid: track.getCid(), name: track.name, kind: track.kind);
|
||||
var stream = await getMediaStream();
|
||||
var transceiverInit = new RTCRtpTransceiverInit(
|
||||
direction: TransceiverDirection.SendOnly,
|
||||
streams: [stream],
|
||||
);
|
||||
// TODO: video encodings and simulcast
|
||||
track.transceiver = await _engine.publisher?.pc.addTransceiver(
|
||||
|
||||
@@ -64,14 +64,18 @@ class RTCEngine with SignalClientDelegate {
|
||||
this.client.delegate = this;
|
||||
}
|
||||
|
||||
Future<JoinResponse> join(String url, String token, JoinOptions? opts) {
|
||||
Future<JoinResponse> join(String url, String token, JoinOptions? opts) async {
|
||||
this.url = url;
|
||||
this.token = token;
|
||||
|
||||
var completer = new Completer<JoinResponse>();
|
||||
joinCompleter = completer;
|
||||
|
||||
client.join(url, token, opts);
|
||||
try {
|
||||
await client.join(url, token, opts);
|
||||
} catch (e) {
|
||||
return Future.error(e);
|
||||
}
|
||||
|
||||
// if it's not complete after 5 seconds, fail
|
||||
new Timer(connectionTimeout, () {
|
||||
|
||||
+29
-13
@@ -1,12 +1,17 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter_webrtc/flutter_webrtc.dart';
|
||||
import 'package:livekit_client/livekit_client.dart';
|
||||
import 'package:web_socket_channel/web_socket_channel.dart';
|
||||
import './track/track.dart';
|
||||
import './version.dart';
|
||||
import './proto/livekit_models.pb.dart';
|
||||
import './proto/livekit_rtc.pb.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import 'logger.dart';
|
||||
import 'track/track.dart';
|
||||
import 'version.dart';
|
||||
import 'proto/livekit_models.pb.dart';
|
||||
import 'proto/livekit_rtc.pb.dart';
|
||||
import '_websocket_api.dart'
|
||||
if (dart.library.io) '_websocket_io.dart'
|
||||
if (dart.library.html) '_websocket_html.dart' as platform;
|
||||
@@ -48,22 +53,33 @@ class SignalClient {
|
||||
|
||||
bool get connected => this._connected;
|
||||
|
||||
join(String url, String token, JoinOptions? options) {
|
||||
url += '/rtc';
|
||||
Future<void> join(String url, String token, JoinOptions? options) async {
|
||||
var rtcUrl = '$url/rtc';
|
||||
var params = _paramsForToken(token);
|
||||
if (options != null && options.autoSubscribe != null) {
|
||||
params += '&auto_subscribe=${options.autoSubscribe! ? '1' : '0'}';
|
||||
}
|
||||
var uri = Uri.parse(url + params);
|
||||
|
||||
platform.connectToWebSocket(uri).then((ws) {
|
||||
try {
|
||||
var ws = await platform.connectToWebSocket(Uri.parse(rtcUrl + params));
|
||||
ws.stream
|
||||
.listen(_handleMessage, onError: _handleError, onDone: _handleDone);
|
||||
_ws = ws;
|
||||
}).catchError((error) {
|
||||
// TODO: ping api endpoint
|
||||
_handleError(error);
|
||||
});
|
||||
} catch (e) {
|
||||
var completer = Completer();
|
||||
var validateUri = Uri.parse('http${rtcUrl.substring(2)}/validate$params');
|
||||
http.get(validateUri).then((response) {
|
||||
if (response.statusCode != 200) {
|
||||
completer.completeError(ConnectError(response.body));
|
||||
} else {
|
||||
completer.completeError(ConnectError());
|
||||
}
|
||||
}).catchError((e) {
|
||||
completer.completeError(ConnectError());
|
||||
});
|
||||
|
||||
return completer.future;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> reconnect(String url, String token) async {
|
||||
@@ -210,7 +226,7 @@ class SignalClient {
|
||||
}
|
||||
|
||||
_handleError(Object error) {
|
||||
// TODO: test HTTP endpoint
|
||||
logger.warning('received websocket error $error');
|
||||
}
|
||||
|
||||
_handleDone() {
|
||||
|
||||
@@ -95,6 +95,20 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.6.5"
|
||||
http:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: http
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.13.3"
|
||||
http_parser:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: http_parser
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "4.0.0"
|
||||
logging:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@@ -158,6 +172,13 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.1"
|
||||
pedantic:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: pedantic
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.11.1"
|
||||
platform:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
@@ -13,6 +13,7 @@ dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
flutter_webrtc: ^0.6.4
|
||||
http: ^0.13.3
|
||||
logging: ^1.0.1
|
||||
protobuf: ^2.0.0
|
||||
tuple: ^2.0.0
|
||||
|
||||
Reference in New Issue
Block a user