feat: 控制指令消息改为protobuf二进制

This commit is contained in:
2026-07-15 17:03:58 +08:00
parent 92ad90cbeb
commit da1730ce19
21 changed files with 658 additions and 147 deletions

View File

@@ -16,6 +16,8 @@ import androidx.appcompat.app.AppCompatActivity;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.ttstd.control.Action;
import com.ttstd.control.ControlMessage;
import com.ttstd.controller.signaling.SignalMessage;
import com.ttstd.controller.signaling.WebSocketClient;
import com.ttstd.controller.view.RemoteTouchView;
@@ -326,55 +328,60 @@ public class MainActivity extends AppCompatActivity {
private void sendTouchCommand(float relX, float relY) {
if (webRtcClient != null) {
JsonObject cmd = new JsonObject();
cmd.addProperty("action", "TOUCH");
cmd.addProperty("x", relX);
cmd.addProperty("y", relY);
webRtcClient.sendControlCommand(cmd.toString());
ControlMessage msg = ControlMessage.newBuilder()
.setAction(Action.TOUCH)
.setX(relX)
.setY(relY)
.build();
webRtcClient.sendControlCommand(msg);
}
}
private void sendSwipeCommand(float relX1, float relY1, float relX2, float relY2, long duration) {
if (webRtcClient != null) {
JsonObject cmd = new JsonObject();
cmd.addProperty("action", "SWIPE");
cmd.addProperty("x1", relX1);
cmd.addProperty("y1", relY1);
cmd.addProperty("x2", relX2);
cmd.addProperty("y2", relY2);
cmd.addProperty("duration", duration);
webRtcClient.sendControlCommand(cmd.toString());
ControlMessage msg = ControlMessage.newBuilder()
.setAction(Action.SWIPE)
.setX1(relX1)
.setY1(relY1)
.setX2(relX2)
.setY2(relY2)
.setDuration(duration)
.build();
webRtcClient.sendControlCommand(msg);
}
}
private void sendKeyCommand(int keyCode, int action) {
if (webRtcClient != null) {
JsonObject cmd = new JsonObject();
cmd.addProperty("action", "KEY");
cmd.addProperty("keyCode", keyCode);
cmd.addProperty("keyAction", action);
webRtcClient.sendControlCommand(cmd.toString());
ControlMessage msg = ControlMessage.newBuilder()
.setAction(Action.KEY)
.setKeyCode(keyCode)
.setKeyAction(action)
.build();
webRtcClient.sendControlCommand(msg);
}
}
private void sendLongPressCommand(float relX, float relY) {
if (webRtcClient != null) {
JsonObject cmd = new JsonObject();
cmd.addProperty("action", "LONG_PRESS");
cmd.addProperty("x", relX);
cmd.addProperty("y", relY);
webRtcClient.sendControlCommand(cmd.toString());
ControlMessage msg = ControlMessage.newBuilder()
.setAction(Action.LONG_PRESS)
.setX(relX)
.setY(relY)
.build();
webRtcClient.sendControlCommand(msg);
}
}
private void sendMotionEventCommand(int action, float relX, float relY) {
if (webRtcClient != null) {
JsonObject cmd = new JsonObject();
cmd.addProperty("action", "MOTION_EVENT");
cmd.addProperty("motionAction", action);
cmd.addProperty("x", relX);
cmd.addProperty("y", relY);
webRtcClient.sendControlCommand(cmd.toString());
ControlMessage msg = ControlMessage.newBuilder()
.setAction(Action.MOTION_EVENT)
.setMotionAction(action)
.setX(relX)
.setY(relY)
.build();
webRtcClient.sendControlCommand(msg);
}
}