fix: remote dialog issues and optimize command protocol

This commit is contained in:
edde746
2026-02-10 09:17:55 +01:00
parent 660267b504
commit 5c3fbfdff8
7 changed files with 30 additions and 290 deletions
@@ -268,13 +268,13 @@ class CompanionRemotePeerService {
appLogger.d('CompanionRemote: Received command: ${command.type}');
if (_shouldSendAck(command)) {
_sendAck(command, hostDeviceName);
_sendAck(command);
}
_commandReceivedController.add(command);
if (command.type == RemoteCommandType.ping) {
_sendPong(hostDeviceName, hostPlatform);
_sendPong();
}
}
} catch (e) {
@@ -375,13 +375,13 @@ class CompanionRemotePeerService {
appLogger.d('CompanionRemote: Received command: ${command.type}');
if (_shouldSendAck(command)) {
_sendAck(command, deviceName);
_sendAck(command);
}
_commandReceivedController.add(command);
if (command.type == RemoteCommandType.ping) {
_sendPong(deviceName, platform);
_sendPong();
}
}
} catch (e) {
@@ -441,7 +441,7 @@ class CompanionRemotePeerService {
_stopPingTimer();
_pingTimer = Timer.periodic(const Duration(seconds: 5), (_) {
if (isConnected) {
sendCommand(RemoteCommand(type: RemoteCommandType.ping, deviceId: _myPeerId ?? 'unknown', deviceName: 'local'));
sendCommand(const RemoteCommand(type: RemoteCommandType.ping));
}
});
}
@@ -458,34 +458,19 @@ class CompanionRemotePeerService {
command.type != RemoteCommandType.deviceInfo;
}
void _sendAck(RemoteCommand command, String deviceName) {
final ackCommand = RemoteCommand(
type: RemoteCommandType.ack,
deviceId: _myPeerId ?? 'unknown',
deviceName: deviceName,
data: {'originalCommand': command.type.toString()},
);
sendCommand(ackCommand);
void _sendAck(RemoteCommand command) {
sendCommand(const RemoteCommand(type: RemoteCommandType.ack));
}
void _sendPong(String deviceName, String platform) {
sendCommand(
RemoteCommand(
type: RemoteCommandType.pong,
deviceId: _myPeerId ?? 'unknown',
deviceName: deviceName,
data: {'platform': platform},
),
);
void _sendPong() {
sendCommand(const RemoteCommand(type: RemoteCommandType.pong));
}
void sendDeviceInfo(String deviceName, String platform) {
sendCommand(
RemoteCommand(
type: RemoteCommandType.deviceInfo,
deviceId: _myPeerId ?? 'unknown',
deviceName: deviceName,
data: {'platform': platform, 'role': _role?.name},
data: {'id': _myPeerId, 'name': deviceName, 'platform': platform, 'role': _role?.name},
),
);
}
@@ -119,8 +119,6 @@ class CompanionRemoteReceiver {
case RemoteCommandType.pong:
case RemoteCommandType.ack:
case RemoteCommandType.deviceInfo:
case RemoteCommandType.capabilitiesRequest:
case RemoteCommandType.capabilitiesResponse:
case RemoteCommandType.disconnect:
break;