Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public NettyChannelBrother(Channel controller, Channel controlled) {
this.controlled = controlled;
}

public void startControll() {
public void startControl() {
NettyUtils.updateControllFlag(controller, Constants.CONTROLLER);
NettyUtils.updateControllDeviceCode(controller, NettyUtils.getDeviceCode(controlled));
NettyUtils.updateControllFlag(controlled, Constants.CONTROLLED);
Expand All @@ -35,7 +35,7 @@ public void startControll() {
}


public void stopControll(byte stopType) {
public void stopControl(byte stopType) {
NettyUtils.updateControllFlag(controller, null);
NettyUtils.updateControllDeviceCode(controller, null);
NettyUtils.updateControllFlag(controlled, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,22 @@ public static synchronized void removeChannelAndBrother(Channel channel) {
channelBrother = channelBrotherMap.remove(NettyUtils.getControllDeviceCode(channel));
}
if (channelBrother != null) {
channelBrother.stopControll(CmdReqCapture.STOP_CAPTURE_CHANNEL_INACTIVE);
channelBrother.stopControl(CmdReqCapture.STOP_CAPTURE_CHANNEL_INACTIVE);
}
}
}

public static void bindChannelBrother(Channel controller, Channel controlled) {
NettyChannelBrother channelBrother = new NettyChannelBrother(controller, controlled);
channelBrother.startControll();
channelBrother.startControl();
channelBrotherMap.putIfAbsent(NettyUtils.getDeviceCode(controlled), channelBrother);

}

public static NettyChannelBrother unbindChannelBrother(byte stopType, Channel controlled) {
NettyChannelBrother channelBrother = channelBrotherMap.get(NettyUtils.getDeviceCode(controlled));
if (channelBrother != null) {
channelBrother.stopControll(stopType);
channelBrother.stopControl(stopType);
channelBrotherMap.remove(NettyUtils.getDeviceCode(controlled));
}
return channelBrother;
Expand All @@ -76,5 +76,12 @@ public static Channel getControlledChannel(Channel controller) {
return null;
}

public static Map<String, Channel> getDeviceCodeChannelMap() {
return deviceCodeChannelMap;
}

public static Map<String, NettyChannelBrother> getChannelBrotherMap() {
return channelBrotherMap;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.github.springstudent.dekstop.server.web.controller;

import io.github.springstudent.dekstop.common.command.CmdReqCapture;
import io.github.springstudent.dekstop.server.netty.NettyChannelBrother;
import io.github.springstudent.dekstop.server.netty.NettyChannelManager;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
* @author tanpenggood
* @date 2025/05/25 8:46
**/
@RestController
@RequestMapping("/web")
public class WebController {

@GetMapping("/info")
public ResponseEntity<Map<String, Map>> info() {
Map<String, Map> result = new HashMap<>();
result.put("deviceCodeChannel", NettyChannelManager.getDeviceCodeChannelMap());
result.put("channelBrother", NettyChannelManager.getChannelBrotherMap());
return ResponseEntity.ok(result);
}

@GetMapping("/unbindChannelBrother/{controlledDeviceCode}")
public ResponseEntity<Map<String, NettyChannelBrother>> unbindChannelBrother(@PathVariable String controlledDeviceCode) {
Map<String, NettyChannelBrother> channelBrotherMap = NettyChannelManager.getChannelBrotherMap();
NettyChannelBrother channelBrother = channelBrotherMap.get(controlledDeviceCode);
Optional.ofNullable(channelBrother).ifPresent(s -> NettyChannelManager.unbindChannelBrother(CmdReqCapture.STOP_CAPTURE, channelBrother.getControlled()));
return ResponseEntity.ok(Collections.singletonMap(controlledDeviceCode, channelBrother));
}

}