Skip to content

Commit

Permalink
Implement voice channel join API
Browse files Browse the repository at this point in the history
  • Loading branch information
SNWCreations committed Jul 4, 2024
1 parent 03a8a1c commit 411b960
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<log4j2.version>2.19.0</log4j2.version>
<jkook.version>0.52.1</jkook.version>
<jkook.version>bfafe506</jkook.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mixin.version>0.12.4+mixin.0.8.5</mixin.version>
<asm.version>9.3</asm.version>
Expand Down
63 changes: 61 additions & 2 deletions src/main/java/snw/kookbc/impl/entity/channel/VoiceChannelImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import snw.jkook.entity.Guild;
import snw.jkook.entity.User;
import snw.jkook.entity.channel.Category;
Expand All @@ -33,8 +34,7 @@

import java.util.*;

import static snw.kookbc.util.GsonUtil.get;
import static snw.kookbc.util.GsonUtil.has;
import static snw.kookbc.util.GsonUtil.*;

public class VoiceChannelImpl extends NonCategoryChannelImpl implements VoiceChannel {
private boolean passwordProtected;
Expand Down Expand Up @@ -149,4 +149,63 @@ public void setQuality(int i) {
this.quality = i;
}

public static final class StreamingInfoImpl implements StreamingInfo {

private final String ip;
private final int port;
private final int rtcp_port;
private final int bitrate;

public StreamingInfoImpl(String ip, int port, int rtcp_port, int bitrate) {
this.ip = ip;
this.port = port;
this.rtcp_port = rtcp_port;
this.bitrate = bitrate;
}


@Override
public String getIp() {
return ip;
}

@Override
public int getPort() {
return port;
}

@Override
public int getRTCPPort() {
return rtcp_port;
}

@Override
public int getBitRate() {
return bitrate;
}
}

@Override
public StreamingInfo requestStreamingInfo(@Nullable String password) {
final Map<String, ?> body = new MapBuilder()
.put("channel_id", getId())
.putIfNotNull("password", password)
.build();
final JsonObject res = client.getNetworkClient().post(HttpAPIRoute.VOICE_JOIN.toFullURL(), body);
return NORMAL_GSON.fromJson(res, StreamingInfoImpl.class);
}

@Override
public StreamingInfo requestStreamingInfo(@Nullable String password, String audioSSRC, String audioPayloadType, boolean rtcpMux) {
final Map<String, ?> body = new MapBuilder()
.put("channel_id", getId())
.putIfNotNull("password", password)
.put("audio_ssrc", audioSSRC)
.put("audio_pt", audioPayloadType)
.put("rtcp_mux", rtcpMux)
.build();
final JsonObject res = client.getNetworkClient().post(HttpAPIRoute.VOICE_JOIN.toFullURL(), body);
return NORMAL_GSON.fromJson(res, StreamingInfoImpl.class);
}

}
5 changes: 5 additions & 0 deletions src/main/java/snw/kookbc/impl/network/HttpAPIRoute.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public enum HttpAPIRoute {
CHANNEL_USER_LIST("/v3/channel/user-list"),
MOVE_USER("/v3/channel/move-user"),

// ------ VOICE ------
VOICE_JOIN("/v3/voice/join"),
VOICE_LIST("/v3/voice/list"),
VOICE_LEAVE("/v3/voice/leave"),

// ------ CHANNEL ROLE (NOT "ROLE") -------
CHANNEL_ROLE_CREATE("/v3/channel-role/create"),
CHANNEL_ROLE_UPDATE("/v3/channel-role/update"),
Expand Down

0 comments on commit 411b960

Please sign in to comment.