Merge branch 'voice-broken' of https://github.com/LAX1DUDE/eaglercraft into voice-broken
This commit is contained in:
commit
81fb43e910
89833
javascript/classes.js
89833
javascript/classes.js
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
|
@ -16,10 +16,9 @@ window.initializeVoiceClient = (() => {
|
|||
const READYSTATE_ABORTED = -1;
|
||||
const READYSTATE_DEVICE_INITIALIZED = 1;
|
||||
|
||||
const TASKSTATE_NONE = -1;
|
||||
const TASKSTATE_LOADING = 0;
|
||||
const TASKSTATE_COMPLETE = 1;
|
||||
const TASKSTATE_FAILED = 2;
|
||||
const PEERSTATE_FAILED = 0;
|
||||
const PEERSTATE_SUCCESS = 1;
|
||||
const PEERSTATE_LOADING = 2;
|
||||
|
||||
class EaglercraftVoicePeer {
|
||||
|
||||
|
@ -54,12 +53,15 @@ window.initializeVoiceClient = (() => {
|
|||
const selfDesc = desc;
|
||||
self.peerConnection.setLocalDescription(selfDesc, () => {
|
||||
self.client.descriptionHandler(self.peerId, JSON.stringify(selfDesc));
|
||||
if (self.client.peerStateInitial != PEERSTATE_SUCCESS) self.client.peerStateInitial = PEERSTATE_SUCCESS;
|
||||
}, (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);
|
||||
});
|
||||
}, (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);
|
||||
});
|
||||
}
|
||||
|
@ -67,6 +69,11 @@ window.initializeVoiceClient = (() => {
|
|||
this.peerConnection.addEventListener("connectionstatechange", (evt) => {
|
||||
if(evt.connectionState === 'disconnected') {
|
||||
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;
|
||||
self.peerConnection.setLocalDescription(selfDesc, () => {
|
||||
self.client.descriptionHandler(self.peerId, JSON.stringify(selfDesc));
|
||||
if (self.client.peerStateDesc != PEERSTATE_SUCCESS) self.client.peerStateDesc = PEERSTATE_SUCCESS;
|
||||
}, (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);
|
||||
});
|
||||
}, (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);
|
||||
});
|
||||
}
|
||||
}, (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);
|
||||
});
|
||||
} catch (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);
|
||||
}
|
||||
}
|
||||
|
@ -112,9 +124,11 @@ window.initializeVoiceClient = (() => {
|
|||
addICECandidate(candidate) {
|
||||
try {
|
||||
this.peerConnection.addIceCandidate(new RTCIceCandidate(JSON.parse(candidate)));
|
||||
if (this.client.peerStateIce != PEERSTATE_SUCCESS) this.client.peerStateIce = PEERSTATE_SUCCESS;
|
||||
} catch (err) {
|
||||
console.error("Failed to parse ice candidate for \"" + self.peerId + "\"! " + err);
|
||||
self.client.signalDisconnect(self.peerId);
|
||||
console.error("Failed to parse ice candidate for \"" + this.peerId + "\"! " + err);
|
||||
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.peerList = new Map();
|
||||
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.descriptionHandler = null;
|
||||
this.peerTrackHandler = null;
|
||||
|
@ -174,7 +192,6 @@ window.initializeVoiceClient = (() => {
|
|||
|
||||
initializeDevices() {
|
||||
if(!this.hasInit) {
|
||||
this.taskState = TASKSTATE_LOADING;
|
||||
const self = this;
|
||||
navigator.mediaDevices.getUserMedia({ audio: true, video: false }).then((stream) => {
|
||||
self.microphoneVolumeAudioContext = new AudioContext();
|
||||
|
@ -187,16 +204,13 @@ window.initializeVoiceClient = (() => {
|
|||
self.localMediaStreamGain.connect(self.localMediaStream);
|
||||
self.localMediaStreamGain.gain.value = 1.0;
|
||||
self.readyState = READYSTATE_DEVICE_INITIALIZED;
|
||||
self.taskState = TASKSTATE_COMPLETE;
|
||||
this.hasInit = true;
|
||||
}).catch((err) => {
|
||||
console.error(err);
|
||||
self.readyState = READYSTATE_ABORTED;
|
||||
self.taskState = TASKSTATE_FAILED;
|
||||
});
|
||||
}else {
|
||||
self.readyState = READYSTATE_DEVICE_INITIALIZED;
|
||||
self.taskState = TASKSTATE_COMPLETE;
|
||||
this.readyState = READYSTATE_DEVICE_INITIALIZED;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -209,8 +223,28 @@ window.initializeVoiceClient = (() => {
|
|||
}
|
||||
}
|
||||
|
||||
getTaskState() {
|
||||
return this.taskState;
|
||||
resetPeerStates() {
|
||||
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() {
|
||||
|
@ -219,9 +253,14 @@ window.initializeVoiceClient = (() => {
|
|||
|
||||
signalConnect(peerId, offer) {
|
||||
if (!this.hasInit) initializeDevices();
|
||||
try {
|
||||
const peerConnection = new RTCPeerConnection({ iceServers: this.ICEServers, optional: [ { DtlsSrtpKeyAgreement: true } ] });
|
||||
const peerInstance = new EaglercraftVoicePeer(this, peerId, peerConnection, offer);
|
||||
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) {
|
||||
|
|
|
@ -265,7 +265,7 @@ public class GuiVoiceMenu extends GuiScreen {
|
|||
EaglerAdapter.glPushMatrix();
|
||||
EaglerAdapter.glTranslatef(-104.0f, 56.5f, 0.0f);
|
||||
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);
|
||||
drawTexturedModalRect(0, 0, 64, 32, 16, 16);
|
||||
}else {
|
||||
|
|
|
@ -56,7 +56,7 @@ public class GuiVoiceOverlay extends Gui {
|
|||
|
||||
voiceGuiIcons.bindTexture();
|
||||
|
||||
if(EaglerAdapter.isKeyDown(mc.gameSettings.voicePTTKey)) {
|
||||
if((mc.currentScreen == null || !mc.currentScreen.blockHotKeys()) && EaglerAdapter.isKeyDown(mc.gameSettings.voicePTTKey)) {
|
||||
long millis = System.currentTimeMillis();
|
||||
if(pttTimer == 0l) {
|
||||
pttTimer = millis;
|
||||
|
|
|
@ -1119,9 +1119,7 @@ public class Minecraft implements Runnable {
|
|||
EaglerAdapter.tickVoice();
|
||||
if (EaglerAdapter.getVoiceStatus() == Voice.VoiceStatus.CONNECTING || EaglerAdapter.getVoiceStatus() == Voice.VoiceStatus.CONNECTED) {
|
||||
|
||||
if(this.currentScreen == null || !this.currentScreen.blockHotKeys()) {
|
||||
EaglerAdapter.activateVoice(EaglerAdapter.isKeyDown(gameSettings.voicePTTKey));
|
||||
}
|
||||
EaglerAdapter.activateVoice((this.currentScreen == null || !this.currentScreen.blockHotKeys()) && EaglerAdapter.isKeyDown(gameSettings.voicePTTKey));
|
||||
|
||||
if (this.theWorld != null && this.thePlayer != null) {
|
||||
HashSet<String> seenPlayers = new HashSet<>();
|
||||
|
|
|
@ -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 boolean voiceAvailableStat = false;
|
||||
|
@ -2144,6 +2142,7 @@ public class EaglerAdapterImpl2 {
|
|||
|
||||
public static final void enableVoice(Voice.VoiceChannel enable) {
|
||||
if (enabledChannel == enable) return;
|
||||
voiceClient.resetPeerStates();
|
||||
if (enabledChannel == Voice.VoiceChannel.PROXIMITY) {
|
||||
for (String username : nearbyPlayers) 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() {
|
||||
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() {
|
||||
return (!voiceAvailable() || !voiceAllowed()) ? Voice.VoiceStatus.UNAVAILABLE :
|
||||
(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;
|
||||
|
|
|
@ -10,10 +10,9 @@ public interface EaglercraftVoiceClient extends JSObject {
|
|||
int READYSTATE_ABORTED = -1;
|
||||
int READYSTATE_DEVICE_INITIALIZED = 1;
|
||||
|
||||
int TASKSTATE_NONE = -1;
|
||||
int TASKSTATE_LOADING = 0;
|
||||
int TASKSTATE_COMPLETE = 1;
|
||||
int TASKSTATE_FAILED = 2;
|
||||
int PEERSTATE_FAILED = 0;
|
||||
int PEERSTATE_SUCCESS = 1;
|
||||
int PEERSTATE_LOADING = 2;
|
||||
|
||||
boolean voiceClientSupported();
|
||||
|
||||
|
@ -35,7 +34,17 @@ public interface EaglercraftVoiceClient extends JSObject {
|
|||
|
||||
void mutePeer(String peerId, boolean muted);
|
||||
|
||||
int getTaskState();
|
||||
void resetPeerStates();
|
||||
|
||||
int getPeerState();
|
||||
|
||||
int getPeerStateConnect();
|
||||
|
||||
int getPeerStateInitial();
|
||||
|
||||
int getPeerStateDesc();
|
||||
|
||||
int getPeerStateIce();
|
||||
|
||||
int getReadyState();
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user