-
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
add57d3
commit faee9b4
Showing
7 changed files
with
158 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
plugin/src/main/java/com/craftmend/openaudiomc/api/impl/VoiceApiImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package com.craftmend.openaudiomc.api.impl; | ||
|
||
import com.craftmend.openaudiomc.api.interfaces.Client; | ||
import com.craftmend.openaudiomc.api.interfaces.VoiceApi; | ||
import com.craftmend.openaudiomc.generic.client.objects.ClientConnection; | ||
import com.craftmend.openaudiomc.generic.client.objects.VoicePeerOptions; | ||
|
||
import java.util.UUID; | ||
|
||
public class VoiceApiImpl implements VoiceApi { | ||
|
||
@Override | ||
public boolean hasPeer(Client haystack, Client needle) { | ||
return hasPeer(haystack, needle.getUser().getUniqueId()); | ||
} | ||
|
||
@Override | ||
public boolean hasPeer(Client haystack, UUID needle) { | ||
ClientConnection clientConnection = (ClientConnection) haystack; | ||
return clientConnection.getRtcSessionManager().isPeer(needle); | ||
} | ||
|
||
@Override | ||
public void updatePeerOptions(Client client, Client peerToUpdate, VoicePeerOptions options) { | ||
client.updatePeerOptions(peerToUpdate, options); | ||
} | ||
|
||
private boolean isProximityPeer(Client haystack, Client needle) { | ||
ClientConnection haystackConnection = (ClientConnection) haystack; | ||
return haystackConnection.getRtcSessionManager().getCurrentProximityPeers().contains(needle.getUser().getUniqueId()); | ||
} | ||
|
||
public boolean isGlobalPeer(Client haystack, Client needle) { | ||
ClientConnection haystackConnection = (ClientConnection) haystack; | ||
return haystackConnection.getRtcSessionManager().getCurrentGlobalPeers().contains(needle.getUser().getUniqueId()); | ||
} | ||
|
||
@Override | ||
public void addStaticPeer(Client client, Client peerToAdd, boolean visible, boolean mutual) { | ||
VoicePeerOptions options = new VoicePeerOptions(); | ||
options.setSpatialAudio(false); | ||
options.setVisible(visible); | ||
|
||
ClientConnection clientConnection = (ClientConnection) client; | ||
ClientConnection peerConnection = (ClientConnection) peerToAdd; | ||
|
||
if (!clientConnection.getRtcSessionManager().isReady() || !peerConnection.getRtcSessionManager().isReady()) { | ||
throw new IllegalStateException("Both clients must be ready (connected and have voice chat enabled) before adding a peer"); | ||
} | ||
|
||
if (isProximityPeer(client, peerToAdd)) { | ||
client.updatePeerOptions(peerToAdd, options); | ||
clientConnection.getRtcSessionManager().getCurrentGlobalPeers().add(peerToAdd.getUser().getUniqueId()); | ||
clientConnection.getRtcSessionManager().getCurrentProximityPeers().remove(peerToAdd.getUser().getUniqueId()); | ||
} else { | ||
clientConnection.getRtcSessionManager().getCurrentGlobalPeers().add(peerToAdd.getUser().getUniqueId()); | ||
clientConnection.getPeerQueue().addSubscribe(peerConnection, clientConnection, options); | ||
} | ||
|
||
if (mutual) { | ||
addStaticPeer(peerToAdd, client, visible, false); | ||
} | ||
} | ||
|
||
@Override | ||
public void removeStaticPeer(Client client, Client peerToRemove, boolean mutual) { | ||
if (isGlobalPeer(client, peerToRemove)) { | ||
ClientConnection clientConnection = (ClientConnection) client; | ||
ClientConnection peerConnection = (ClientConnection) peerToRemove; | ||
clientConnection.getRtcSessionManager().getCurrentGlobalPeers().remove(peerToRemove.getUser().getUniqueId()); | ||
clientConnection.getPeerQueue().drop(peerConnection.getRtcSessionManager().getStreamKey()); | ||
} | ||
|
||
if (mutual) { | ||
removeStaticPeer(peerToRemove, client, false); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
plugin/src/main/java/com/craftmend/openaudiomc/api/interfaces/VoiceApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.craftmend.openaudiomc.api.interfaces; | ||
|
||
import com.craftmend.openaudiomc.generic.client.objects.VoicePeerOptions; | ||
|
||
import java.util.UUID; | ||
|
||
public interface VoiceApi { | ||
|
||
/* | ||
* The VoiceApi contains registry, as well as control endpoints for voice-chat related features. | ||
* This implementation is only available on the Spigot instance, even if the plugin is running in a BungeeCord/Velocity or Vistas network. | ||
* Accessing this API on a non-spigot instance will result in undefined behavior or runtime exceptions. | ||
*/ | ||
|
||
/** | ||
* Register a client as a voice-chat peer | ||
* @param haystack The client that will be the host | ||
* @param needle The client that will be the peer | ||
* @return true if the client was registered, false if the client was already registered | ||
*/ | ||
boolean hasPeer(Client haystack, Client needle); | ||
|
||
/** | ||
* Register a client as a voice-chat peer | ||
* @param haystack The client that will be the host | ||
* @param needle The client that will be the peer | ||
* @return true if the client was registered, false if the client was already registered | ||
*/ | ||
boolean hasPeer(Client haystack, UUID needle); | ||
|
||
/** | ||
* Push new options for a peer, changing how its rendered in the client | ||
* @param client The web client that should receive this update | ||
* @param peerToUpdate The peer that should be updated | ||
* @param options The new options | ||
*/ | ||
void updatePeerOptions(Client client, Client peerToUpdate, VoicePeerOptions options); | ||
|
||
/** | ||
* Add a peer (partner) to someone's voice chat. | ||
* This would let the client hear the peerToAdd as a global voice (without spatial audio/distance) until it's removed. | ||
* @param client The web client that should receive this update | ||
* @param peerToAdd The peer that should be added | ||
* @param visible Whether the peer should be visible in the client | ||
* @param mutual Whether the peer should also hear the client (repeat the call for mutual) | ||
*/ | ||
void addStaticPeer(Client client, Client peerToAdd, boolean visible, boolean mutual); | ||
|
||
/** | ||
* Remove a global peer from someone's voice chat. | ||
* This would remove a static peer if they have been added through addStaticPeer, but not | ||
* if they have been added through the regular voice-chat system. | ||
* @param client The web client that should receive this update | ||
* @param peerToRemove The peer that should be removed | ||
* @param mutual Whether the peer should also stop hearing the client (repeat the call for mutual) | ||
*/ | ||
void removeStaticPeer(Client client, Client peerToRemove, boolean mutual); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
public enum RtcBlockReason { | ||
|
||
IN_DISABLED_REGION | ||
IN_DISABLED_REGION, | ||
EXEMPTED_FROM_PEER_TICKING | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters