166 lines
3.9 KiB
Java
166 lines
3.9 KiB
Java
package org.webrtc;
|
|
|
|
import java.nio.ByteBuffer;
|
|
public class DataChannel {
|
|
private long nativeDataChannel;
|
|
private long nativeObserver;
|
|
|
|
public static class Buffer {
|
|
public final boolean binary;
|
|
public final ByteBuffer data;
|
|
|
|
@CalledByNative("Buffer")
|
|
public Buffer(ByteBuffer byteBuffer, boolean z2) {
|
|
this.data = byteBuffer;
|
|
this.binary = z2;
|
|
}
|
|
}
|
|
|
|
public static class Init {
|
|
|
|
/* renamed from: id reason: collision with root package name */
|
|
public int f2882id = -1;
|
|
public int maxRetransmitTimeMs = -1;
|
|
public int maxRetransmits = -1;
|
|
public boolean negotiated;
|
|
public boolean ordered = true;
|
|
public String protocol = "";
|
|
|
|
@CalledByNative("Init")
|
|
public int getId() {
|
|
return this.f2882id;
|
|
}
|
|
|
|
@CalledByNative("Init")
|
|
public int getMaxRetransmitTimeMs() {
|
|
return this.maxRetransmitTimeMs;
|
|
}
|
|
|
|
@CalledByNative("Init")
|
|
public int getMaxRetransmits() {
|
|
return this.maxRetransmits;
|
|
}
|
|
|
|
@CalledByNative("Init")
|
|
public boolean getNegotiated() {
|
|
return this.negotiated;
|
|
}
|
|
|
|
@CalledByNative("Init")
|
|
public boolean getOrdered() {
|
|
return this.ordered;
|
|
}
|
|
|
|
@CalledByNative("Init")
|
|
public String getProtocol() {
|
|
return this.protocol;
|
|
}
|
|
}
|
|
|
|
public interface Observer {
|
|
@CalledByNative("Observer")
|
|
void onBufferedAmountChange(long j);
|
|
|
|
@CalledByNative("Observer")
|
|
void onMessage(Buffer buffer);
|
|
|
|
@CalledByNative("Observer")
|
|
void onStateChange();
|
|
}
|
|
|
|
public enum State {
|
|
CONNECTING,
|
|
OPEN,
|
|
CLOSING,
|
|
CLOSED;
|
|
|
|
@CalledByNative("State")
|
|
public static State fromNativeIndex(int i) {
|
|
return values()[i];
|
|
}
|
|
}
|
|
|
|
@CalledByNative
|
|
public DataChannel(long j) {
|
|
this.nativeDataChannel = j;
|
|
}
|
|
|
|
private void checkDataChannelExists() {
|
|
if (this.nativeDataChannel == 0) {
|
|
throw new IllegalStateException("DataChannel has been disposed.");
|
|
}
|
|
}
|
|
|
|
private native long nativeBufferedAmount();
|
|
|
|
private native void nativeClose();
|
|
|
|
private native int nativeId();
|
|
|
|
private native String nativeLabel();
|
|
|
|
private native long nativeRegisterObserver(Observer observer);
|
|
|
|
private native boolean nativeSend(byte[] bArr, boolean z2);
|
|
|
|
private native State nativeState();
|
|
|
|
private native void nativeUnregisterObserver(long j);
|
|
|
|
public long bufferedAmount() {
|
|
checkDataChannelExists();
|
|
return nativeBufferedAmount();
|
|
}
|
|
|
|
public void close() {
|
|
checkDataChannelExists();
|
|
nativeClose();
|
|
}
|
|
|
|
public void dispose() {
|
|
checkDataChannelExists();
|
|
JniCommon.nativeReleaseRef(this.nativeDataChannel);
|
|
this.nativeDataChannel = 0;
|
|
}
|
|
|
|
@CalledByNative
|
|
public long getNativeDataChannel() {
|
|
return this.nativeDataChannel;
|
|
}
|
|
|
|
public int id() {
|
|
checkDataChannelExists();
|
|
return nativeId();
|
|
}
|
|
|
|
public String label() {
|
|
checkDataChannelExists();
|
|
return nativeLabel();
|
|
}
|
|
|
|
public void registerObserver(Observer observer) {
|
|
checkDataChannelExists();
|
|
long j = this.nativeObserver;
|
|
if (j != 0) {
|
|
nativeUnregisterObserver(j);
|
|
}
|
|
this.nativeObserver = nativeRegisterObserver(observer);
|
|
}
|
|
|
|
public boolean send(Buffer buffer) {
|
|
checkDataChannelExists();
|
|
byte[] bArr = new byte[buffer.data.remaining()];
|
|
buffer.data.get(bArr);
|
|
return nativeSend(bArr, buffer.binary);
|
|
}
|
|
|
|
public State state() {
|
|
checkDataChannelExists();
|
|
return nativeState();
|
|
}
|
|
|
|
public void unregisterObserver() {
|
|
checkDataChannelExists();
|
|
nativeUnregisterObserver(this.nativeObserver);
|
|
}
|
|
}
|