Skip to content

Commit

Permalink
feat: add reconnect field to connect method
Browse files Browse the repository at this point in the history
  • Loading branch information
rIIh committed Jan 7, 2021
1 parent 9102243 commit 6362e78
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class MagxClient {
),
);

Future<Room> connect(String id) async {
Future<Room> connect(String id, {bool reconnect}) async {
final user = await verify();
final descriptionResponse = await getRoom(id);
if (descriptionResponse.isSuccessful == false || user.isSuccessful == false) {
Expand All @@ -150,7 +150,7 @@ class MagxClient {
final description = descriptionResponse.body;
print('[MagxClient.connect]: ${description.clients}');
if (description.clients.contains(user.body.id)) {
return _connectRoom(RoomData.fromJson(description.toJson()), reconnect: true);
return _connectRoom(RoomData.fromJson(description.toJson()), reconnect: reconnect ?? true);
} else {
final joinResponse = await api.service.joinRoom(description.id).then(
(value) => value.isSuccessful
Expand All @@ -160,7 +160,7 @@ class MagxClient {
),
);
if (joinResponse.isSuccessful) {
return _connectRoom(joinResponse.body);
return _connectRoom(joinResponse.body, reconnect: false);
}
}
return null;
Expand Down Expand Up @@ -188,7 +188,7 @@ class MagxClient {
: value.copyWith(body: null),
);
if (data.isSuccessful) {
return data.copyWith(body: await _connectRoom(data.body));
return data.copyWith(body: await _connectRoom(data.body, reconnect: false));
}
return data.copyWith(body: null);
}
Expand Down

0 comments on commit 6362e78

Please sign in to comment.