Skip to content

Commit

Permalink
Include ClientPeerAddEvent to addStaticPeer
Browse files Browse the repository at this point in the history
  • Loading branch information
Mindgamesnl committed May 5, 2024
1 parent 641f43b commit 77cc8c3
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.craftmend.openaudiomc.generic.api.implementaions;

import com.craftmend.openaudiomc.OpenAudioMc;
import com.craftmend.openaudiomc.api.EventApi;
import com.craftmend.openaudiomc.api.VoiceApi;
import com.craftmend.openaudiomc.api.clients.Client;
import com.craftmend.openaudiomc.api.events.client.ClientPeerAddEvent;
import com.craftmend.openaudiomc.api.interfaces.AudioApi;
import com.craftmend.openaudiomc.api.voice.CustomPlayerFilter;
import com.craftmend.openaudiomc.api.voice.VoicePeerOptions;
import com.craftmend.openaudiomc.generic.client.objects.ClientConnection;
Expand Down Expand Up @@ -93,13 +96,17 @@ public void addStaticPeer(Client client, Client peerToAdd, boolean visible, bool
throw new IllegalStateException("Both clients must be ready (connected and have voice chat enabled) before adding a peer");
}

if (isProximityPeer(client, peerToAdd)) {
updatePeerOptions(client, peerToAdd, options);
clientConnection.getRtcSessionManager().getCurrentGlobalPeers().add(peerToAdd.getActor().getUniqueId());
clientConnection.getRtcSessionManager().getCurrentProximityPeers().remove(peerToAdd.getActor().getUniqueId());
} else {
clientConnection.getRtcSessionManager().getCurrentGlobalPeers().add(peerToAdd.getActor().getUniqueId());
clientConnection.getPeerQueue().addSubscribe(peerConnection, clientConnection, options);
// fire event
ClientPeerAddEvent event = (ClientPeerAddEvent) EventApi.getInstance().callEvent(new ClientPeerAddEvent(client, peerToAdd, options));
if (!event.isCancelled()) {
if (isProximityPeer(client, peerToAdd)) {
updatePeerOptions(client, peerToAdd, options);
clientConnection.getRtcSessionManager().getCurrentGlobalPeers().add(peerToAdd.getActor().getUniqueId());
clientConnection.getRtcSessionManager().getCurrentProximityPeers().remove(peerToAdd.getActor().getUniqueId());
} else {
clientConnection.getRtcSessionManager().getCurrentGlobalPeers().add(peerToAdd.getActor().getUniqueId());
clientConnection.getPeerQueue().addSubscribe(peerConnection, clientConnection, options);
}
}

if (mutual) {
Expand Down

0 comments on commit 77cc8c3

Please sign in to comment.