Skip to content

Commit

Permalink
Add MediaConnectException. (#422)
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwebrtc authored Dec 11, 2023
1 parent d684856 commit c36c7e4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/src/core/engine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,12 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {

logger.fine('Waiting for engine to connect...');

// wait until engine is connected
// wait until primary pc is connected
await events.waitFor<EnginePeerStateUpdatedEvent>(
filter: (event) => event.isPrimary && event.state.isConnected(),
duration: this.connectOptions.timeouts.connection,
onTimeout: () => throw ConnectException(
'Timed out waiting for EnginePeerStateUpdatedEvent'),
onTimeout: () => throw MediaConnectException(
'Timed out waiting for PeerConnection to connect, please check your network for ice connectivity'),
);

_updateConnectionState(ConnectionState.connected);
Expand Down Expand Up @@ -646,7 +646,7 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
await events.waitFor<EnginePeerStateUpdatedEvent>(
filter: (event) => event.isPrimary && event.state.isConnected(),
duration: connectOptions.timeouts.iceRestart,
onTimeout: () => throw ConnectException(),
onTimeout: () => throw MediaConnectException('ice restart failed'),
);
}
}
Expand Down
9 changes: 9 additions & 0 deletions lib/src/exceptions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ class ConnectException extends LiveKitException {
ConnectException([String msg = 'Failed to connect to server']) : super._(msg);
}

/// An exception occured while attempting to disconnect.
/// Common reasons:
/// - Network condition is not good.
/// - SFU deploy behind a NAT and not configured correctly.
/// - Need a turn relay server but not configured.
class MediaConnectException extends LiveKitException {
MediaConnectException([String msg = 'Ice connection failed']) : super._(msg);
}

/// An internal state of the SDK is not correct and can not continue to execute.
/// This should not occur frequently.
class UnexpectedStateException extends LiveKitException {
Expand Down

0 comments on commit c36c7e4

Please sign in to comment.