flutter_chromecast_example icon indicating copy to clipboard operation
flutter_chromecast_example copied to clipboard

Disconnect not working

Open gabrielrf97 opened this issue 4 years ago • 2 comments

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.

gabrielrf97 avatar Oct 24 '20 00:10 gabrielrf97

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; }

Cdriic avatar Jan 29 '21 16:01 Cdriic

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.

gabrielrf97 avatar Feb 24 '21 19:02 gabrielrf97