Skip to content

Commit

Permalink
fix close youtube chat
Browse files Browse the repository at this point in the history
  • Loading branch information
LezdCS committed May 30, 2024
1 parent 1210178 commit 296e0b6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/src/core/utils/youtube_chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class YoutubeChat {
this.videoId,
);

void closeStream() {
_chatStreamController.close();
}

// Function to fetch the initial continuation token
Future<String?> fetchInitialContinuationToken() async {
var headers = {
Expand Down Expand Up @@ -123,6 +127,7 @@ class YoutubeChat {
}

while (continuationToken != null) {
if(_chatStreamController.isClosed) return;
continuationToken = await fetchChatMessages(continuationToken);
await Future.delayed(const Duration(seconds: 5)); // 5-second pause
}
Expand Down
1 change: 1 addition & 0 deletions lib/src/presentation/controllers/chat_view_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ class ChatViewController extends GetxController
}

for (YoutubeChat y in youtubeChatToRemove) {
y.closeStream();
youtubeChats.removeWhere((yc) => yc.videoId == y.videoId);
}
}
Expand Down

0 comments on commit 296e0b6

Please sign in to comment.