mirror of https://github.com/Genymobile/scrcpy
Extract ControlChannel class
This prevents many components from depending on the whole DesktopConnection.issue4703
parent
a7cf4daf3b
commit
25f1e703b7
@ -0,0 +1,33 @@
|
||||
package com.genymobile.scrcpy;
|
||||
|
||||
import android.net.LocalSocket;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public final class ControlChannel {
|
||||
private final InputStream inputStream;
|
||||
private final OutputStream outputStream;
|
||||
|
||||
private final ControlMessageReader reader = new ControlMessageReader();
|
||||
private final DeviceMessageWriter writer = new DeviceMessageWriter();
|
||||
|
||||
public ControlChannel(LocalSocket controlSocket) throws IOException {
|
||||
this.inputStream = controlSocket.getInputStream();
|
||||
this.outputStream = controlSocket.getOutputStream();
|
||||
}
|
||||
|
||||
public ControlMessage recv() throws IOException {
|
||||
ControlMessage msg = reader.next();
|
||||
while (msg == null) {
|
||||
reader.readFrom(inputStream);
|
||||
msg = reader.next();
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void send(DeviceMessage msg) throws IOException {
|
||||
writer.writeTo(msg, outputStream);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue