reconnect method
Implementation
Future<bool> reconnect({String? sourceId, String? destinationId}) async {
_castSession =
CastSession(sourceId: sourceId, destinationId: destinationId);
bool connected = await connect();
if (!connected) {
return false;
}
_mediaChannel = MediaChannel.Create(
socket: _socket, sourceId: sourceId, destinationId: destinationId);
_mediaChannel!.sendMessage({'type': 'GET_STATUS'});
// now wait for the media to actually get a status?
bool didReconnect = await _waitForMediaStatus();
if (didReconnect) {
log.fine('reconnecting successful!');
try {
castSessionController.add(_castSession);
} catch (e) {
log.severe(
"Could not add the CastSession to the CastSession Stream Controller: events will not be triggered");
log.severe(e.toString());
log.info("Closed? ${castSessionController.isClosed}");
}
try {
castMediaStatusController.add(_castSession!.castMediaStatus);
} catch (e) {
log.severe(
"Could not add the CastMediaStatus to the CastSession Stream Controller: events will not be triggered");
log.severe(e.toString());
log.info("Closed? ${castMediaStatusController.isClosed}");
}
}
return didReconnect;
}