flutter_chromecast_example
flutter_chromecast_example copied to clipboard
Disconnect not working
Disconnect feature is not working in current example. (master, HEAD a0cf9d45c12dd68a237c74619443aa203b6a5cf4).
After the sample app successfully connects to the cast device, by clicking in the top left tab bar icon and calling disconnect, with the current declaration:
void disconnect() async { if (null != _castSender) { await _castSender.disconnect(); final prefs = await SharedPreferences.getInstance(); prefs.remove('cast_session_host'); prefs.remove('cast_session_port'); prefs.remove('cast_session_device_name'); prefs.remove('cast_session_device_type'); prefs.remove('cast_session_sender_id'); prefs.remove('cast_session_destination_id'); setState(() { _castSender = null; _servicesFound = false; _castConnected = false; _discover(); }); } }
the app does not disconnect from the cast device.
Disconnect feature is not working in current example. (master, HEAD a0cf9d4).
After the sample app successfully connects to the cast device, by clicking in the top left tab bar icon and calling disconnect, with the current declaration:
void disconnect() async { if (null != _castSender) { await _castSender.disconnect(); final prefs = await SharedPreferences.getInstance(); prefs.remove('cast_session_host'); prefs.remove('cast_session_port'); prefs.remove('cast_session_device_name'); prefs.remove('cast_session_device_type'); prefs.remove('cast_session_sender_id'); prefs.remove('cast_session_destination_id'); setState(() { _castSender = null; _servicesFound = false; _castConnected = false; _discover(); }); } }
the app does not disconnect from the cast device.
Solution: (cast_sender.dart)
Future<bool> disconnect() async { if (null != _connectionChannel && null != _castSession?.castMediaStatus) { _connectionChannel.sendMessage({ 'type': 'CLOSE', 'sessionId': _castSession.castMediaStatus.sessionId, }); } if (null != _socket) { await _socket.destroy(); } _dispose(); connectionDidClose = true; return true; }
TO
Future<bool> disconnect() async { if (null != _connectionChannel) { _connectionChannel.sendMessage({ 'type': 'CLOSE', }); } if (null != _socket) { await _socket.destroy(); } _dispose(); connectionDidClose = true; return true; }
That actually works. I'm facing some network issues here, which lead me to undeterministic tests. I expect them to be solved later on and I'll comment again.