Skip to content

Commit

Permalink
fix: Fixed a bug that prevented the connection from being completed.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathrunet committed Jun 3, 2024
1 parent d1a5ac1 commit 87914bb
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 94 deletions.
50 changes: 25 additions & 25 deletions packages/masamune_agora/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -406,154 +406,154 @@ packages:
path: "../../katana"
relative: true
source: path
version: "2.14.0"
version: "2.15.0"
katana_auth:
dependency: "direct overridden"
description:
path: "../../katana_auth"
relative: true
source: path
version: "2.9.1"
version: "2.9.2"
katana_form:
dependency: "direct overridden"
description:
path: "../../katana_form"
relative: true
source: path
version: "2.12.17"
version: "2.13.1"
katana_functions:
dependency: "direct overridden"
description:
path: "../../katana_functions"
relative: true
source: path
version: "2.7.0"
version: "2.7.1"
katana_indicator:
dependency: "direct overridden"
description:
path: "../../katana_indicator"
relative: true
source: path
version: "2.2.4"
version: "2.2.5"
katana_listenables:
dependency: "direct overridden"
description:
path: "../../katana_listenables"
relative: true
source: path
version: "2.2.6"
version: "2.2.7"
katana_listenables_annotation:
dependency: "direct overridden"
description:
path: "../../katana_listenables_annotation"
relative: true
source: path
version: "2.1.6"
version: "2.1.7"
katana_localization:
dependency: "direct overridden"
description:
path: "../../katana_localization"
relative: true
source: path
version: "2.3.8"
version: "2.3.9"
katana_localization_annotation:
dependency: "direct overridden"
description:
path: "../../katana_localization_annotation"
relative: true
source: path
version: "2.2.7"
version: "2.2.8"
katana_logger:
dependency: "direct overridden"
description:
path: "../../katana_logger"
relative: true
source: path
version: "2.2.6"
version: "2.2.7"
katana_model:
dependency: "direct overridden"
description:
path: "../../katana_model"
relative: true
source: path
version: "2.26.15"
version: "2.26.16"
katana_model_local:
dependency: "direct overridden"
description:
path: "../../katana_model_local"
relative: true
source: path
version: "2.13.26"
version: "2.13.27"
katana_prefs:
dependency: "direct overridden"
description:
path: "../../katana_prefs"
relative: true
source: path
version: "2.2.6"
version: "2.2.7"
katana_prefs_annotation:
dependency: "direct overridden"
description:
path: "../../katana_prefs_annotation"
relative: true
source: path
version: "2.1.6"
version: "2.1.7"
katana_router:
dependency: "direct overridden"
description:
path: "../../katana_router"
relative: true
source: path
version: "2.2.13"
version: "2.2.16"
katana_router_annotation:
dependency: "direct overridden"
description:
path: "../../katana_router_annotation"
relative: true
source: path
version: "2.1.7"
version: "2.1.9"
katana_scoped:
dependency: "direct overridden"
description:
path: "../../katana_scoped"
relative: true
source: path
version: "2.5.12"
version: "2.5.13"
katana_shorten:
dependency: "direct overridden"
description:
path: "../../katana_shorten"
relative: true
source: path
version: "2.1.6"
version: "2.1.7"
katana_storage:
dependency: "direct overridden"
description:
path: "../../katana_storage"
relative: true
source: path
version: "2.2.7"
version: "2.2.8"
katana_theme:
dependency: "direct overridden"
description:
path: "../../katana_theme"
relative: true
source: path
version: "2.6.0"
version: "2.6.1"
katana_theme_annotation:
dependency: "direct overridden"
description:
path: "../../katana_theme_annotation"
relative: true
source: path
version: "2.2.4"
version: "2.2.5"
katana_ui:
dependency: "direct overridden"
description:
path: "../../katana_ui"
relative: true
source: path
version: "2.10.0"
version: "2.10.1"
leak_tracker:
dependency: transitive
description:
Expand Down Expand Up @@ -600,21 +600,21 @@ packages:
path: "../../masamune"
relative: true
source: path
version: "2.13.31"
version: "2.13.35"
masamune_agora:
dependency: "direct main"
description:
path: ".."
relative: true
source: path
version: "2.4.76"
version: "2.4.81"
masamune_annotation:
dependency: "direct overridden"
description:
path: "../../masamune_annotation"
relative: true
source: path
version: "2.6.9"
version: "2.6.10"
matcher:
dependency: transitive
description:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ class AgoraTokenFunctionsAction
const AgoraTokenFunctionsAction({
required this.channelName,
this.clientRole = AgoraClientRole.audience,
});
this.uid,
this.account,
}) : assert(uid != null || account != null, "uid or account is required.");

/// Name of the channel to be created.
///
Expand All @@ -42,6 +44,16 @@ class AgoraTokenFunctionsAction
/// チャンネルの作成者の役割。
final AgoraClientRole clientRole;

/// User ID.
///
/// ユーザーID。
final int? uid;

/// Account Name.
///
/// アカウント名。
final String? account;

@override
String get action => "agora_token";

Expand All @@ -51,6 +63,8 @@ class AgoraTokenFunctionsAction
"role":
clientRole == AgoraClientRole.audience ? "audience" : "broadcaster",
"name": channelName,
if (uid != null) "uid": uid,
if (account != null) "account": account,
};
}

Expand Down
13 changes: 8 additions & 5 deletions packages/masamune_agora/lib/src/agora_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,9 @@ class AgoraController
userAccount: userName,
);
await _initializeCompleter?.future;
if (_localUserNumber == null || _localName == null) {
throw Exception("Failed to register local user account.");
}
} catch (e) {
_initializeCompleter?.completeError(e);
_initializeCompleter = null;
Expand Down Expand Up @@ -522,6 +525,7 @@ class AgoraController
final res = await adapter.functionsAdapter.execute(
AgoraTokenFunctionsAction(
channelName: channelName,
uid: _localUserNumber,
clientRole: AgoraClientRole.values
.firstWhereOrNull((item) => item.index == clientRole.index) ??
AgoraClientRole.audience,
Expand Down Expand Up @@ -716,10 +720,11 @@ class AgoraController
int retried = 0;
ConnectionStateType? connectionState;
do {
_engine?.joinChannelWithUserAccount(
_engine?.joinChannel(
token: _token ?? "",
channelId: channelName,
userAccount: userName,
uid: _localUserNumber!,
options: const ChannelMediaOptions(),
);
await _connectingCompleter?.future;
connectionState = await _engine?.getConnectionState();
Expand Down Expand Up @@ -1367,13 +1372,11 @@ class AgoraController
AgoraLoggerEvent.userNumberKey: remoteUid,
AgoraLoggerEvent.isLocalUserKey: false,
});
// FIXME: ここで待たないと画面が更新されないことがある
await Future.delayed(const Duration(milliseconds: 100));
notifyListeners();
final userInfo = await _engine?.getUserInfoByUid(remoteUid);
if (userInfo != null) {
user._setName(userInfo.userAccount ?? "");
}
notifyListeners();
}

void _sendLog(AgoraLoggerEvent event, {DynamicMap? parameters}) {
Expand Down
1 change: 1 addition & 0 deletions packages/masamune_agora/lib/src/agora_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ class _AgoraScreenState extends State<AgoraScreen> {
if (AgoraController._engine == null || channel.isEmpty) {
return const Empty();
}

if (remoteState == RemoteVideoState.remoteVideoStateStopped ||
remoteState == RemoteVideoState.remoteVideoStateFailed) {
return Container(
Expand Down
11 changes: 11 additions & 0 deletions packages/masamune_agora/lib/src/agora_user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,15 @@ class AgoraUser extends ChangeNotifier {
_status = status;
notifyListeners();
}

@override
bool operator ==(Object other) => hashCode == other.hashCode;

@override
int get hashCode =>
number.hashCode ^
isLocalUser.hashCode ^
channel.hashCode ^
name.hashCode ^
status.hashCode;
}
Loading

0 comments on commit 87914bb

Please sign in to comment.