Merge branch 'voice-broken' of https://github.com/LAX1DUDE/eaglercraft into voice-broken

This commit is contained in:
LAX1DUDE 2022-07-20 23:00:51 -07:00
commit 81fb43e910
8 changed files with 44997 additions and 44952 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -16,10 +16,9 @@ window.initializeVoiceClient = (() => {
const READYSTATE_ABORTED = -1; const READYSTATE_ABORTED = -1;
const READYSTATE_DEVICE_INITIALIZED = 1; const READYSTATE_DEVICE_INITIALIZED = 1;
const TASKSTATE_NONE = -1; const PEERSTATE_FAILED = 0;
const TASKSTATE_LOADING = 0; const PEERSTATE_SUCCESS = 1;
const TASKSTATE_COMPLETE = 1; const PEERSTATE_LOADING = 2;
const TASKSTATE_FAILED = 2;
class EaglercraftVoicePeer { class EaglercraftVoicePeer {
@ -54,12 +53,15 @@ window.initializeVoiceClient = (() => {
const selfDesc = desc; const selfDesc = desc;
self.peerConnection.setLocalDescription(selfDesc, () => { self.peerConnection.setLocalDescription(selfDesc, () => {
self.client.descriptionHandler(self.peerId, JSON.stringify(selfDesc)); self.client.descriptionHandler(self.peerId, JSON.stringify(selfDesc));
if (self.client.peerStateInitial != PEERSTATE_SUCCESS) self.client.peerStateInitial = PEERSTATE_SUCCESS;
}, (err) => { }, (err) => {
console.error("Failed to set local description for \"" + self.peerId + "\"! " + err); console.error("Failed to set local description for \"" + self.peerId + "\"! " + err);
if (self.client.peerStateInitial == PEERSTATE_LOADING) self.client.peerStateInitial = PEERSTATE_FAILED;
self.client.signalDisconnect(self.peerId); self.client.signalDisconnect(self.peerId);
}); });
}, (err) => { }, (err) => {
console.error("Failed to set create offer for \"" + self.peerId + "\"! " + err); console.error("Failed to set create offer for \"" + self.peerId + "\"! " + err);
if (self.client.peerStateInitial == PEERSTATE_LOADING) self.client.peerStateInitial = PEERSTATE_FAILED;
self.client.signalDisconnect(self.peerId); self.client.signalDisconnect(self.peerId);
}); });
} }
@ -67,6 +69,11 @@ window.initializeVoiceClient = (() => {
this.peerConnection.addEventListener("connectionstatechange", (evt) => { this.peerConnection.addEventListener("connectionstatechange", (evt) => {
if(evt.connectionState === 'disconnected') { if(evt.connectionState === 'disconnected') {
self.client.signalDisconnect(self.peerId); self.client.signalDisconnect(self.peerId);
} else if (evt.connectionState === 'connected') {
if (self.client.peerState != PEERSTATE_SUCCESS) self.client.peerState = PEERSTATE_SUCCESS;
} else if (evt.connectionState === 'failed') {
if (self.client.peerState == PEERSTATE_LOADING) self.client.peerState = PEERSTATE_FAILED;
self.client.signalDisconnect(self.peerId);
} }
}); });
@ -90,21 +97,26 @@ window.initializeVoiceClient = (() => {
const selfDesc = desc; const selfDesc = desc;
self.peerConnection.setLocalDescription(selfDesc, () => { self.peerConnection.setLocalDescription(selfDesc, () => {
self.client.descriptionHandler(self.peerId, JSON.stringify(selfDesc)); self.client.descriptionHandler(self.peerId, JSON.stringify(selfDesc));
if (self.client.peerStateDesc != PEERSTATE_SUCCESS) self.client.peerStateDesc = PEERSTATE_SUCCESS;
}, (err) => { }, (err) => {
console.error("Failed to set local description for \"" + self.peerId + "\"! " + err); console.error("Failed to set local description for \"" + self.peerId + "\"! " + err);
if (self.client.peerStateDesc == PEERSTATE_LOADING) self.client.peerStateDesc = PEERSTATE_FAILED;
self.client.signalDisconnect(self.peerId); self.client.signalDisconnect(self.peerId);
}); });
}, (err) => { }, (err) => {
console.error("Failed to create answer for \"" + self.peerId + "\"! " + err); console.error("Failed to create answer for \"" + self.peerId + "\"! " + err);
if (self.client.peerStateDesc == PEERSTATE_LOADING) self.client.peerStateDesc = PEERSTATE_FAILED;
self.client.signalDisconnect(self.peerId); self.client.signalDisconnect(self.peerId);
}); });
} }
}, (err) => { }, (err) => {
console.error("Failed to set remote description for \"" + self.peerId + "\"! " + err); console.error("Failed to set remote description for \"" + self.peerId + "\"! " + err);
if (self.client.peerStateDesc == PEERSTATE_LOADING) self.client.peerStateDesc = PEERSTATE_FAILED;
self.client.signalDisconnect(self.peerId); self.client.signalDisconnect(self.peerId);
}); });
} catch (err) { } catch (err) {
console.error("Failed to parse remote description for \"" + self.peerId + "\"! " + err); console.error("Failed to parse remote description for \"" + self.peerId + "\"! " + err);
if (self.client.peerStateDesc == PEERSTATE_LOADING) self.client.peerStateDesc = PEERSTATE_FAILED;
self.client.signalDisconnect(self.peerId); self.client.signalDisconnect(self.peerId);
} }
} }
@ -112,9 +124,11 @@ window.initializeVoiceClient = (() => {
addICECandidate(candidate) { addICECandidate(candidate) {
try { try {
this.peerConnection.addIceCandidate(new RTCIceCandidate(JSON.parse(candidate))); this.peerConnection.addIceCandidate(new RTCIceCandidate(JSON.parse(candidate)));
if (this.client.peerStateIce != PEERSTATE_SUCCESS) this.client.peerStateIce = PEERSTATE_SUCCESS;
} catch (err) { } catch (err) {
console.error("Failed to parse ice candidate for \"" + self.peerId + "\"! " + err); console.error("Failed to parse ice candidate for \"" + this.peerId + "\"! " + err);
self.client.signalDisconnect(self.peerId); if (this.client.peerStateIce == PEERSTATE_LOADING) this.client.peerStateIce = PEERSTATE_FAILED;
this.client.signalDisconnect(this.peerId);
} }
} }
@ -127,7 +141,11 @@ window.initializeVoiceClient = (() => {
this.hasInit = false; this.hasInit = false;
this.peerList = new Map(); this.peerList = new Map();
this.readyState = READYSTATE_NONE; this.readyState = READYSTATE_NONE;
this.taskState = TASKSTATE_NONE; this.peerState = PEERSTATE_LOADING;
this.peerStateConnect = PEERSTATE_LOADING;
this.peerStateInitial = PEERSTATE_LOADING;
this.peerStateDesc = PEERSTATE_LOADING;
this.peerStateIce = PEERSTATE_LOADING;
this.iceCandidateHandler = null; this.iceCandidateHandler = null;
this.descriptionHandler = null; this.descriptionHandler = null;
this.peerTrackHandler = null; this.peerTrackHandler = null;
@ -174,7 +192,6 @@ window.initializeVoiceClient = (() => {
initializeDevices() { initializeDevices() {
if(!this.hasInit) { if(!this.hasInit) {
this.taskState = TASKSTATE_LOADING;
const self = this; const self = this;
navigator.mediaDevices.getUserMedia({ audio: true, video: false }).then((stream) => { navigator.mediaDevices.getUserMedia({ audio: true, video: false }).then((stream) => {
self.microphoneVolumeAudioContext = new AudioContext(); self.microphoneVolumeAudioContext = new AudioContext();
@ -187,16 +204,13 @@ window.initializeVoiceClient = (() => {
self.localMediaStreamGain.connect(self.localMediaStream); self.localMediaStreamGain.connect(self.localMediaStream);
self.localMediaStreamGain.gain.value = 1.0; self.localMediaStreamGain.gain.value = 1.0;
self.readyState = READYSTATE_DEVICE_INITIALIZED; self.readyState = READYSTATE_DEVICE_INITIALIZED;
self.taskState = TASKSTATE_COMPLETE;
this.hasInit = true; this.hasInit = true;
}).catch((err) => { }).catch((err) => {
console.error(err); console.error(err);
self.readyState = READYSTATE_ABORTED; self.readyState = READYSTATE_ABORTED;
self.taskState = TASKSTATE_FAILED;
}); });
}else { }else {
self.readyState = READYSTATE_DEVICE_INITIALIZED; this.readyState = READYSTATE_DEVICE_INITIALIZED;
self.taskState = TASKSTATE_COMPLETE;
} }
} }
@ -209,8 +223,28 @@ window.initializeVoiceClient = (() => {
} }
} }
getTaskState() { resetPeerStates() {
return this.taskState; this.peerState = this.peerStateConnect = this.peerStateInitial = this.peerStateDesc = this.peerStateIce = PEERSTATE_LOADING;
}
getPeerState() {
return this.peerState;
}
getPeerStateConnect() {
return this.peerStateConnect;
}
getPeerStateInitial() {
return this.peerStateInitial;
}
getPeerStateDesc() {
return this.peerStateDesc;
}
getPeerStateIce() {
return this.peerStateIce;
} }
getReadyState() { getReadyState() {
@ -219,9 +253,14 @@ window.initializeVoiceClient = (() => {
signalConnect(peerId, offer) { signalConnect(peerId, offer) {
if (!this.hasInit) initializeDevices(); if (!this.hasInit) initializeDevices();
try {
const peerConnection = new RTCPeerConnection({ iceServers: this.ICEServers, optional: [ { DtlsSrtpKeyAgreement: true } ] }); const peerConnection = new RTCPeerConnection({ iceServers: this.ICEServers, optional: [ { DtlsSrtpKeyAgreement: true } ] });
const peerInstance = new EaglercraftVoicePeer(this, peerId, peerConnection, offer); const peerInstance = new EaglercraftVoicePeer(this, peerId, peerConnection, offer);
this.peerList.set(peerId, peerInstance); this.peerList.set(peerId, peerInstance);
if (this.peerStateConnect != PEERSTATE_SUCCESS) this.peerStateConnect = PEERSTATE_SUCCESS;
} catch (e) {
if (this.peerStateConnect == PEERSTATE_LOADING) this.peerStateConnect = PEERSTATE_FAILED;
}
} }
signalDescription(peerId, descJSON) { signalDescription(peerId, descJSON) {

View File

@ -265,7 +265,7 @@ public class GuiVoiceMenu extends GuiScreen {
EaglerAdapter.glPushMatrix(); EaglerAdapter.glPushMatrix();
EaglerAdapter.glTranslatef(-104.0f, 56.5f, 0.0f); EaglerAdapter.glTranslatef(-104.0f, 56.5f, 0.0f);
EaglerAdapter.glScalef(0.7f, 0.7f, 0.7f); EaglerAdapter.glScalef(0.7f, 0.7f, 0.7f);
if(EaglerAdapter.isKeyDown(mc.gameSettings.voicePTTKey)) { if((mc.currentScreen == null || !mc.currentScreen.blockHotKeys()) && EaglerAdapter.isKeyDown(mc.gameSettings.voicePTTKey)) {
EaglerAdapter.glColor4f(0.9f, 0.4f, 0.4f, 1.0f); EaglerAdapter.glColor4f(0.9f, 0.4f, 0.4f, 1.0f);
drawTexturedModalRect(0, 0, 64, 32, 16, 16); drawTexturedModalRect(0, 0, 64, 32, 16, 16);
}else { }else {

View File

@ -56,7 +56,7 @@ public class GuiVoiceOverlay extends Gui {
voiceGuiIcons.bindTexture(); voiceGuiIcons.bindTexture();
if(EaglerAdapter.isKeyDown(mc.gameSettings.voicePTTKey)) { if((mc.currentScreen == null || !mc.currentScreen.blockHotKeys()) && EaglerAdapter.isKeyDown(mc.gameSettings.voicePTTKey)) {
long millis = System.currentTimeMillis(); long millis = System.currentTimeMillis();
if(pttTimer == 0l) { if(pttTimer == 0l) {
pttTimer = millis; pttTimer = millis;

View File

@ -1119,9 +1119,7 @@ public class Minecraft implements Runnable {
EaglerAdapter.tickVoice(); EaglerAdapter.tickVoice();
if (EaglerAdapter.getVoiceStatus() == Voice.VoiceStatus.CONNECTING || EaglerAdapter.getVoiceStatus() == Voice.VoiceStatus.CONNECTED) { if (EaglerAdapter.getVoiceStatus() == Voice.VoiceStatus.CONNECTING || EaglerAdapter.getVoiceStatus() == Voice.VoiceStatus.CONNECTED) {
if(this.currentScreen == null || !this.currentScreen.blockHotKeys()) { EaglerAdapter.activateVoice((this.currentScreen == null || !this.currentScreen.blockHotKeys()) && EaglerAdapter.isKeyDown(gameSettings.voicePTTKey));
EaglerAdapter.activateVoice(EaglerAdapter.isKeyDown(gameSettings.voicePTTKey));
}
if (this.theWorld != null && this.thePlayer != null) { if (this.theWorld != null && this.thePlayer != null) {
HashSet<String> seenPlayers = new HashSet<>(); HashSet<String> seenPlayers = new HashSet<>();

View File

@ -1995,8 +1995,6 @@ public class EaglerAdapterImpl2 {
} }
// implementation notes - try to only connect to client in GLOBAL or LOCAL not both
private static EaglercraftVoiceClient voiceClient = null; private static EaglercraftVoiceClient voiceClient = null;
private static boolean voiceAvailableStat = false; private static boolean voiceAvailableStat = false;
@ -2144,6 +2142,7 @@ public class EaglerAdapterImpl2 {
public static final void enableVoice(Voice.VoiceChannel enable) { public static final void enableVoice(Voice.VoiceChannel enable) {
if (enabledChannel == enable) return; if (enabledChannel == enable) return;
voiceClient.resetPeerStates();
if (enabledChannel == Voice.VoiceChannel.PROXIMITY) { if (enabledChannel == Voice.VoiceChannel.PROXIMITY) {
for (String username : nearbyPlayers) voiceClient.signalDisconnect(username, false); for (String username : nearbyPlayers) voiceClient.signalDisconnect(username, false);
for (String username : recentlyNearbyPlayers) voiceClient.signalDisconnect(username, false); for (String username : recentlyNearbyPlayers) voiceClient.signalDisconnect(username, false);
@ -2262,10 +2261,13 @@ public class EaglerAdapterImpl2 {
public static final Voice.VoiceChannel getVoiceChannel() { public static final Voice.VoiceChannel getVoiceChannel() {
return enabledChannel; return enabledChannel;
} }
public static final boolean voicePeerErrored() {
return voiceClient.getPeerState() == EaglercraftVoiceClient.PEERSTATE_FAILED || voiceClient.getPeerStateConnect() == EaglercraftVoiceClient.PEERSTATE_FAILED || voiceClient.getPeerStateInitial() == EaglercraftVoiceClient.PEERSTATE_FAILED || voiceClient.getPeerStateDesc() == EaglercraftVoiceClient.PEERSTATE_FAILED || voiceClient.getPeerStateIce() == EaglercraftVoiceClient.PEERSTATE_FAILED;
}
public static final Voice.VoiceStatus getVoiceStatus() { public static final Voice.VoiceStatus getVoiceStatus() {
return (!voiceAvailable() || !voiceAllowed()) ? Voice.VoiceStatus.UNAVAILABLE : return (!voiceAvailable() || !voiceAllowed()) ? Voice.VoiceStatus.UNAVAILABLE :
(voiceClient.getReadyState() != EaglercraftVoiceClient.READYSTATE_DEVICE_INITIALIZED ? (voiceClient.getReadyState() != EaglercraftVoiceClient.READYSTATE_DEVICE_INITIALIZED ?
Voice.VoiceStatus.CONNECTING : Voice.VoiceStatus.CONNECTED); Voice.VoiceStatus.CONNECTING : (voicePeerErrored() ? Voice.VoiceStatus.UNAVAILABLE : Voice.VoiceStatus.CONNECTED));
} }
private static boolean talkStatus = false; private static boolean talkStatus = false;

View File

@ -10,10 +10,9 @@ public interface EaglercraftVoiceClient extends JSObject {
int READYSTATE_ABORTED = -1; int READYSTATE_ABORTED = -1;
int READYSTATE_DEVICE_INITIALIZED = 1; int READYSTATE_DEVICE_INITIALIZED = 1;
int TASKSTATE_NONE = -1; int PEERSTATE_FAILED = 0;
int TASKSTATE_LOADING = 0; int PEERSTATE_SUCCESS = 1;
int TASKSTATE_COMPLETE = 1; int PEERSTATE_LOADING = 2;
int TASKSTATE_FAILED = 2;
boolean voiceClientSupported(); boolean voiceClientSupported();
@ -35,7 +34,17 @@ public interface EaglercraftVoiceClient extends JSObject {
void mutePeer(String peerId, boolean muted); void mutePeer(String peerId, boolean muted);
int getTaskState(); void resetPeerStates();
int getPeerState();
int getPeerStateConnect();
int getPeerStateInitial();
int getPeerStateDesc();
int getPeerStateIce();
int getReadyState(); int getReadyState();