-
-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from ZhouYixun/scrcpy_dev
Scrcpy dev
- Loading branch information
Showing
27 changed files
with
556 additions
and
539 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,30 @@ | ||
package com.sonic.agent; | ||
|
||
import com.sonic.agent.tools.SpringTool; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Import; | ||
|
||
/** | ||
* @author ZhouYiXun | ||
* @des Agent端启动类 | ||
* @date 2021/08/16 19:26 | ||
*/ | ||
@Import(SpringTool.class) | ||
@SpringBootApplication | ||
public class AgentApplication { | ||
@Value("${sonic.agent.port}") | ||
private int port; | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(AgentApplication.class, args); | ||
} | ||
|
||
@Bean | ||
public TomcatServletWebServerFactory servletContainer(){ | ||
return new TomcatServletWebServerFactory(port) ; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/com/sonic/agent/netty/MarshallingCodeCFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.sonic.agent.netty; | ||
|
||
import io.netty.handler.codec.marshalling.*; | ||
import org.jboss.marshalling.MarshallerFactory; | ||
import org.jboss.marshalling.Marshalling; | ||
import org.jboss.marshalling.MarshallingConfiguration; | ||
|
||
public final class MarshallingCodeCFactory { | ||
public static MarshallingDecoder buildMarshallingDecoder() { | ||
final MarshallerFactory marshallerFactory = Marshalling.getProvidedMarshallerFactory("serial"); | ||
final MarshallingConfiguration configuration = new MarshallingConfiguration(); | ||
configuration.setVersion(5); | ||
UnmarshallerProvider provider = new DefaultUnmarshallerProvider(marshallerFactory, configuration); | ||
MarshallingDecoder decoder = new MarshallingDecoder(provider, 10*1024*1024); | ||
return decoder; | ||
} | ||
|
||
public static MarshallingEncoder buildMarshallingEncoder() { | ||
final MarshallerFactory marshallerFactory = Marshalling.getProvidedMarshallerFactory("serial"); | ||
final MarshallingConfiguration configuration = new MarshallingConfiguration(); | ||
configuration.setVersion(5); | ||
MarshallerProvider provider = new DefaultMarshallerProvider(marshallerFactory, configuration); | ||
MarshallingEncoder encoder = new MarshallingEncoder(provider); | ||
return encoder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.sonic.agent.netty; | ||
|
||
import io.netty.bootstrap.Bootstrap; | ||
import io.netty.channel.*; | ||
import io.netty.channel.nio.NioEventLoopGroup; | ||
import io.netty.channel.socket.SocketChannel; | ||
import io.netty.channel.socket.nio.NioSocketChannel; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.ApplicationArguments; | ||
import org.springframework.boot.ApplicationRunner; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
@Component | ||
public class NettyClient implements ApplicationRunner { | ||
private final Logger logger = LoggerFactory.getLogger(NettyClient.class); | ||
private NioEventLoopGroup group = new NioEventLoopGroup(4); | ||
private Channel channel; | ||
private Bootstrap bootstrap; | ||
@Value("${sonic.server.transport-port}") | ||
private int serverPort; | ||
@Value("${sonic.server.host}") | ||
private String serverHost; | ||
@Value("${sonic.agent.port}") | ||
private int agentPort; | ||
@Value("${sonic.agent.host}") | ||
private String agentHost; | ||
@Value("${sonic.agent.key}") | ||
private String key; | ||
@Value("${spring.version}") | ||
private String version; | ||
|
||
@Override | ||
public void run(ApplicationArguments args) { | ||
group = new NioEventLoopGroup(); | ||
bootstrap = new Bootstrap() | ||
.group(group) | ||
.option(ChannelOption.TCP_NODELAY, true) | ||
.channel(NioSocketChannel.class) | ||
.handler(new ChannelInitializer<SocketChannel>() { | ||
@Override | ||
protected void initChannel(SocketChannel socketChannel) throws Exception { | ||
socketChannel.pipeline().addLast(MarshallingCodeCFactory.buildMarshallingDecoder()); | ||
socketChannel.pipeline().addLast(MarshallingCodeCFactory.buildMarshallingEncoder()); | ||
socketChannel.pipeline().addLast(new SecurityHandler(NettyClient.this, key, agentHost, agentPort, version)); | ||
} | ||
}); | ||
doConnect(); | ||
} | ||
|
||
protected void doConnect() { | ||
if (channel != null && channel.isActive()) { | ||
return; | ||
} | ||
ChannelFuture future = bootstrap.connect(serverHost, serverPort); | ||
future.addListener((ChannelFutureListener) futureListener -> { | ||
if (futureListener.isSuccess()) { | ||
channel = futureListener.channel(); | ||
} else { | ||
logger.info("连接到服务器{}:{}失败!10s后重连...", serverHost, serverPort); | ||
futureListener.channel().eventLoop().schedule(() -> doConnect(), 10, TimeUnit.SECONDS); | ||
} | ||
}); | ||
} | ||
} |
Oops, something went wrong.