Begin debugging datachannels

This commit is contained in:
ayunami2000 2022-08-19 20:40:48 -04:00
parent c191024041
commit c767bc15c0
5 changed files with 15441 additions and 15483 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -404,16 +404,6 @@ window.initializeLANClient = (() => {
} }
}); });
/*
this.peerConnection.addEventListener("datachannel", (evt) => {
self.channel = evt.channel;
self.remoteDataChannelHandler(self.channel);
evt.channel.addEventListener("message", (evt) => {
self.remotePacketHandler(evt.data);
});
});
*/
this.channel = this.peerConnection.createDataChannel("lan"); this.channel = this.peerConnection.createDataChannel("lan");
this.channel.addEventListener("open", (evt) => { this.channel.addEventListener("open", (evt) => {
@ -421,8 +411,9 @@ window.initializeLANClient = (() => {
}); });
this.channel.addEventListener("message", (evt) => { this.channel.addEventListener("message", (evt) => {
console.log(evt.data);
self.remotePacketHandler(evt.data); self.remotePacketHandler(evt.data);
}); }, false);
this.peerConnection.createOffer((desc) => { this.peerConnection.createOffer((desc) => {
const selfDesc = desc; const selfDesc = desc;
@ -520,24 +511,13 @@ window.initializeLANServer = (() => {
} }
}); });
/*
this.dataChannel = this.peerConnection.createDataChannel("lan");
this.dataChannel.addEventListener("open", (evt) => {
self.client.remoteClientDataChannelHandler(self.peerId, self.dataChannel);
});
this.dataChannel.addEventListener("message", (evt) => {
self.client.remoteClientPacketHandler(self.peerId, evt.data);
});
*/
this.peerConnection.addEventListener("datachannel", (evt) => { this.peerConnection.addEventListener("datachannel", (evt) => {
self.dataChannel = evt.channel; self.dataChannel = evt.channel;
self.client.remoteClientDataChannelHandler(self.peerId, self.dataChannel); self.client.remoteClientDataChannelHandler(self.peerId, self.dataChannel);
self.dataChannel.addEventListener("message", (evt) => { self.dataChannel.addEventListener("message", (evt) => {
console.log(evt.data);
self.client.remoteClientPacketHandler(self.peerId, evt.data); self.client.remoteClientPacketHandler(self.peerId, evt.data);
}); }, false);
}); });
this.peerConnection.addEventListener("connectionstatechange", (evt) => { this.peerConnection.addEventListener("connectionstatechange", (evt) => {
@ -669,6 +649,7 @@ window.initializeLANServer = (() => {
sendPacketToRemoteClient(peerId, buffer) { sendPacketToRemoteClient(peerId, buffer) {
var thePeer = this.peerList.get(peerId); var thePeer = this.peerList.get(peerId);
if((typeof thePeer !== "undefined") && thePeer !== null) { if((typeof thePeer !== "undefined") && thePeer !== null) {
console.log(123);
thePeer.dataChannel.send(buffer); thePeer.dataChannel.send(buffer);
} }
} }

View File

@ -7,6 +7,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Consumer; import java.util.function.Consumer;
import net.lax1dude.eaglercraft.sp.ipc.IPCPacket0CPlayerChannel;
import net.lax1dude.eaglercraft.sp.relay.pkt.*; import net.lax1dude.eaglercraft.sp.relay.pkt.*;
public class IntegratedServerLAN { public class IntegratedServerLAN {
@ -251,14 +252,15 @@ public class IntegratedServerLAN {
long millis = System.currentTimeMillis(); long millis = System.currentTimeMillis();
do { do {
LANPeerEvent evt; LANPeerEvent evt;
if((evt = EaglerAdapter.serverLANGetEvent(clientId)) != null) { while((evt = EaglerAdapter.serverLANGetEvent(clientId)) != null && evt instanceof LANPeerEvent.LANPeerICECandidateEvent) {
// skip ice candidates
}
if(evt != null) {
if(evt instanceof LANPeerEvent.LANPeerDataChannelEvent) { if(evt instanceof LANPeerEvent.LANPeerDataChannelEvent) {
EaglerAdapter.enableChannel("NET|" + clientId); EaglerAdapter.enableChannel("NET|" + clientId);
IntegratedServer.sendIPCPacket(new IPCPacket0CPlayerChannel(clientId, true));
state = CONNECTED; state = CONNECTED;
return; return;
}else if(evt instanceof LANPeerEvent.LANPeerICECandidateEvent) {
// ignore
return;
}else if(evt instanceof LANPeerEvent.LANPeerDisconnectEvent) { }else if(evt instanceof LANPeerEvent.LANPeerDisconnectEvent) {
System.err.println("LAN client '" + clientId + "' disconnected while waiting for connection"); System.err.println("LAN client '" + clientId + "' disconnected while waiting for connection");
}else { }else {
@ -305,8 +307,10 @@ public class IntegratedServerLAN {
} }
} }
if(state == CONNECTED) { if(state == CONNECTED) {
PKT pk = EaglerAdapter.recieveFromIntegratedServer(clientId); PKT pk;
EaglerAdapter.serverLANWritePacket(clientId, pk.data); while((pk = EaglerAdapter.recieveFromIntegratedServer("NET|" + clientId)) != null) {
EaglerAdapter.serverLANWritePacket(clientId, pk.data);
}
} }
} }
} }
@ -314,6 +318,7 @@ public class IntegratedServerLAN {
protected void disconnect() { protected void disconnect() {
if(!dead) { if(!dead) {
if(state == CONNECTED) { if(state == CONNECTED) {
IntegratedServer.sendIPCPacket(new IPCPacket0CPlayerChannel(clientId, false));
EaglerAdapter.disableChannel("NET|" + clientId); EaglerAdapter.disableChannel("NET|" + clientId);
} }
state = CLOSED; state = CLOSED;

View File

@ -3704,12 +3704,6 @@ public class EaglerAdapterImpl2 {
private static boolean clientLANinit = false; private static boolean clientLANinit = false;
private static final List<byte[]> clientLANPacketBuffer = new ArrayList<>(); private static final List<byte[]> clientLANPacketBuffer = new ArrayList<>();
public static final int LAN_CLIENT_INIT_FAILED = -2;
public static final int LAN_CLIENT_FAILED = -1;
public static final int LAN_CLIENT_DISCONNECTED = 0;
public static final int LAN_CLIENT_CONNECTING = 1;
public static final int LAN_CLIENT_CONNECTED = 2;
private static String clientICECandidate = null; private static String clientICECandidate = null;
private static String clientDescription = null; private static String clientDescription = null;
private static boolean clientDataChannelOpen = false; private static boolean clientDataChannelOpen = false;
@ -3886,18 +3880,10 @@ public class EaglerAdapterImpl2 {
} }
} }
public static final boolean serverLANServerOpen() {
return true;
}
public static final void serverLANCloseServer() { public static final void serverLANCloseServer() {
rtcLANServer.signalRemoteDisconnect(""); rtcLANServer.signalRemoteDisconnect("");
} }
public static final LANPeerEvent serverLANGetEvent() {
return serverLANEventBuffer.size() > 0 ? serverLANEventBuffer.remove(0) : null;
}
public static final LANPeerEvent serverLANGetEvent(String clientId) { public static final LANPeerEvent serverLANGetEvent(String clientId) {
if(serverLANEventBuffer.size() > 0) { if(serverLANEventBuffer.size() > 0) {
Iterator<LANPeerEvent> i = serverLANEventBuffer.iterator(); Iterator<LANPeerEvent> i = serverLANEventBuffer.iterator();
@ -3914,22 +3900,6 @@ public class EaglerAdapterImpl2 {
} }
} }
public static final <T extends LANPeerEvent> T serverLANGetEvent(String clientId, Class<T> eventType) {
if(serverLANEventBuffer.size() > 0) {
Iterator<LANPeerEvent> i = serverLANEventBuffer.iterator();
while(i.hasNext()) {
LANPeerEvent evt = i.next();
if(evt.getPeerId().equals(clientId) && eventType.isInstance(evt)) {
i.remove();
return (T)evt;
}
}
return null;
}else {
return null;
}
}
public static final void serverLANWritePacket(String peer, byte[] data) { public static final void serverLANWritePacket(String peer, byte[] data) {
ArrayBuffer arr = ArrayBuffer.create(data.length); ArrayBuffer arr = ArrayBuffer.create(data.length);
Uint8Array.create(arr).set(data); Uint8Array.create(arr).set(data);