Begin debugging datachannels
This commit is contained in:
parent
c191024041
commit
c767bc15c0
30846
javascript/classes.js
30846
javascript/classes.js
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -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.addEventListener("open", (evt) => {
|
||||
|
@ -421,8 +411,9 @@ window.initializeLANClient = (() => {
|
|||
});
|
||||
|
||||
this.channel.addEventListener("message", (evt) => {
|
||||
console.log(evt.data);
|
||||
self.remotePacketHandler(evt.data);
|
||||
});
|
||||
}, false);
|
||||
|
||||
this.peerConnection.createOffer((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) => {
|
||||
self.dataChannel = evt.channel;
|
||||
self.client.remoteClientDataChannelHandler(self.peerId, self.dataChannel);
|
||||
self.dataChannel.addEventListener("message", (evt) => {
|
||||
console.log(evt.data);
|
||||
self.client.remoteClientPacketHandler(self.peerId, evt.data);
|
||||
});
|
||||
}, false);
|
||||
});
|
||||
|
||||
this.peerConnection.addEventListener("connectionstatechange", (evt) => {
|
||||
|
@ -669,6 +649,7 @@ window.initializeLANServer = (() => {
|
|||
sendPacketToRemoteClient(peerId, buffer) {
|
||||
var thePeer = this.peerList.get(peerId);
|
||||
if((typeof thePeer !== "undefined") && thePeer !== null) {
|
||||
console.log(123);
|
||||
thePeer.dataChannel.send(buffer);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.lax1dude.eaglercraft.sp.ipc.IPCPacket0CPlayerChannel;
|
||||
import net.lax1dude.eaglercraft.sp.relay.pkt.*;
|
||||
|
||||
public class IntegratedServerLAN {
|
||||
|
@ -251,14 +252,15 @@ public class IntegratedServerLAN {
|
|||
long millis = System.currentTimeMillis();
|
||||
do {
|
||||
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) {
|
||||
EaglerAdapter.enableChannel("NET|" + clientId);
|
||||
IntegratedServer.sendIPCPacket(new IPCPacket0CPlayerChannel(clientId, true));
|
||||
state = CONNECTED;
|
||||
return;
|
||||
}else if(evt instanceof LANPeerEvent.LANPeerICECandidateEvent) {
|
||||
// ignore
|
||||
return;
|
||||
}else if(evt instanceof LANPeerEvent.LANPeerDisconnectEvent) {
|
||||
System.err.println("LAN client '" + clientId + "' disconnected while waiting for connection");
|
||||
}else {
|
||||
|
@ -305,8 +307,10 @@ public class IntegratedServerLAN {
|
|||
}
|
||||
}
|
||||
if(state == CONNECTED) {
|
||||
PKT pk = EaglerAdapter.recieveFromIntegratedServer(clientId);
|
||||
EaglerAdapter.serverLANWritePacket(clientId, pk.data);
|
||||
PKT pk;
|
||||
while((pk = EaglerAdapter.recieveFromIntegratedServer("NET|" + clientId)) != null) {
|
||||
EaglerAdapter.serverLANWritePacket(clientId, pk.data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -314,6 +318,7 @@ public class IntegratedServerLAN {
|
|||
protected void disconnect() {
|
||||
if(!dead) {
|
||||
if(state == CONNECTED) {
|
||||
IntegratedServer.sendIPCPacket(new IPCPacket0CPlayerChannel(clientId, false));
|
||||
EaglerAdapter.disableChannel("NET|" + clientId);
|
||||
}
|
||||
state = CLOSED;
|
||||
|
|
|
@ -3704,12 +3704,6 @@ public class EaglerAdapterImpl2 {
|
|||
private static boolean clientLANinit = false;
|
||||
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 clientDescription = null;
|
||||
private static boolean clientDataChannelOpen = false;
|
||||
|
@ -3885,19 +3879,11 @@ public class EaglerAdapterImpl2 {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static final boolean serverLANServerOpen() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static final void serverLANCloseServer() {
|
||||
rtcLANServer.signalRemoteDisconnect("");
|
||||
}
|
||||
|
||||
public static final LANPeerEvent serverLANGetEvent() {
|
||||
return serverLANEventBuffer.size() > 0 ? serverLANEventBuffer.remove(0) : null;
|
||||
}
|
||||
|
||||
public static final LANPeerEvent serverLANGetEvent(String clientId) {
|
||||
if(serverLANEventBuffer.size() > 0) {
|
||||
Iterator<LANPeerEvent> i = serverLANEventBuffer.iterator();
|
||||
|
@ -3913,22 +3899,6 @@ public class EaglerAdapterImpl2 {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
ArrayBuffer arr = ArrayBuffer.create(data.length);
|
||||
|
|
Loading…
Reference in New Issue
Block a user