本文整理汇总了Java中org.webrtc.DataChannel类的典型用法代码示例。如果您正苦于以下问题:Java DataChannel类的具体用法?Java DataChannel怎么用?Java DataChannel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DataChannel类属于org.webrtc包,在下文中一共展示了DataChannel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dataChannelSend
import org.webrtc.DataChannel; //导入依赖的package包/类
void dataChannelSend(int dataChannelId, String data, String type) {
DataChannel dataChannel = dataChannels.get(dataChannelId);
if (dataChannel != null) {
byte[] byteArray;
if (type.equals("text")) {
try {
byteArray = data.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
Log.d(TAG, "Could not encode text string as UTF-8.");
return;
}
} else if (type.equals("binary")) {
byteArray = Base64.decode(data, Base64.NO_WRAP);
} else {
Log.e(TAG, "Unsupported data type: " + type);
return;
}
ByteBuffer byteBuffer = ByteBuffer.wrap(byteArray);
DataChannel.Buffer buffer = new DataChannel.Buffer(byteBuffer, type.equals("binary"));
dataChannel.send(buffer);
} else {
Log.d(TAG, "dataChannelSend() dataChannel is null");
}
}
示例2: onMessage
import org.webrtc.DataChannel; //导入依赖的package包/类
@Override
public void onMessage(DataChannel.Buffer buffer) {
WritableMap params = Arguments.createMap();
params.putInt("id", mId);
params.putInt("peerConnectionId", peerConnectionId);
byte[] bytes;
if (buffer.data.hasArray()) {
bytes = buffer.data.array();
} else {
bytes = new byte[buffer.data.remaining()];
buffer.data.get(bytes);
}
if (buffer.binary) {
params.putString("type", "binary");
params.putString("data", Base64.encodeToString(bytes, Base64.NO_WRAP));
} else {
params.putString("type", "text");
params.putString("data", new String(bytes, Charset.forName("UTF-8")));
}
webRTCModule.sendEvent("dataChannelReceiveMessage", params);
}
示例3: handleAnswerCall
import org.webrtc.DataChannel; //导入依赖的package包/类
private void handleAnswerCall(Intent intent) {
if (callState != CallState.STATE_LOCAL_RINGING) {
Log.w(TAG, "Can only answer from ringing!");
return;
}
if (peerConnection == null || dataChannel == null || recipient == null || callId == null) {
throw new AssertionError("assert");
}
DatabaseFactory.getSmsDatabase(this).insertReceivedCall(recipient.getNumber());
this.peerConnection.setAudioEnabled(true);
this.peerConnection.setVideoEnabled(true);
this.dataChannel.send(new DataChannel.Buffer(ByteBuffer.wrap(Data.newBuilder().setConnected(Connected.newBuilder().setId(this.callId)).build().toByteArray()), false));
intent.putExtra(EXTRA_CALL_ID, callId);
intent.putExtra(EXTRA_REMOTE_NUMBER, recipient.getNumber());
handleCallConnected(intent);
}
示例4: handleDenyCall
import org.webrtc.DataChannel; //导入依赖的package包/类
private void handleDenyCall(Intent intent) {
if (callState != CallState.STATE_LOCAL_RINGING) {
Log.w(TAG, "Can only deny from ringing!");
return;
}
if (recipient == null || callId == null || dataChannel == null) {
throw new AssertionError("assert");
}
this.dataChannel.send(new DataChannel.Buffer(ByteBuffer.wrap(Data.newBuilder().setHangup(Hangup.newBuilder().setId(this.callId)).build().toByteArray()), false));
sendMessage(this.recipient, SignalServiceCallMessage.forHangup(new HangupMessage(this.callId)));
DatabaseFactory.getSmsDatabase(this).insertMissedCall(recipient.getNumber());
this.terminate();
}
示例5: sendMessage
import org.webrtc.DataChannel; //导入依赖的package包/类
/**
* Send a message to the remote client through the direct connection.
*
* @param message The message to send
* @param completionListener A listener to receive a notification on the success of the asynchronous operation
*/
public void sendMessage(String message, final Respoke.TaskCompletionListener completionListener) {
if (isActive()) {
JSONObject jsonMessage = new JSONObject();
try {
jsonMessage.put("message", message);
byte[] rawMessage = jsonMessage.toString().getBytes(Charset.forName("UTF-8"));
ByteBuffer directData = ByteBuffer.allocateDirect(rawMessage.length);
directData.put(rawMessage);
directData.flip();
DataChannel.Buffer data = new DataChannel.Buffer(directData, false);
if (dataChannel.send(data)) {
Respoke.postTaskSuccess(completionListener);
} else {
Respoke.postTaskError(completionListener, "Error sending message");
}
} catch (JSONException e) {
Respoke.postTaskError(completionListener, "Unable to encode message to JSON");
}
} else {
Respoke.postTaskError(completionListener, "DataChannel not in an open state");
}
}
示例6: peerConnectionDidOpenDataChannel
import org.webrtc.DataChannel; //导入依赖的package包/类
/**
* Notify the direct connection instance that the peer connection has opened the specified data channel
*
* @param newDataChannel The DataChannel that has opened
*/
public void peerConnectionDidOpenDataChannel(DataChannel newDataChannel) {
if (null != dataChannel) {
// Replacing the previous connection, so disable observer messages from the old instance
dataChannel.unregisterObserver();
} else {
new Handler(Looper.getMainLooper()).post(new Runnable() {
public void run() {
if (null != listenerReference) {
Listener listener = listenerReference.get();
if (null != listener) {
listener.onStart(RespokeDirectConnection.this);
}
}
}
});
}
dataChannel = newDataChannel;
newDataChannel.registerObserver(this);
}
示例7: createDataChannel
import org.webrtc.DataChannel; //导入依赖的package包/类
void createDataChannel(String label, ReadableMap config) {
DataChannel.Init init = new DataChannel.Init();
if (config != null) {
if (config.hasKey("id")) {
init.id = config.getInt("id");
}
if (config.hasKey("ordered")) {
init.ordered = config.getBoolean("ordered");
}
if (config.hasKey("maxRetransmitTime")) {
init.maxRetransmitTimeMs = config.getInt("maxRetransmitTime");
}
if (config.hasKey("maxRetransmits")) {
init.maxRetransmits = config.getInt("maxRetransmits");
}
if (config.hasKey("protocol")) {
init.protocol = config.getString("protocol");
}
if (config.hasKey("negotiated")) {
init.negotiated = config.getBoolean("negotiated");
}
}
DataChannel dataChannel = peerConnection.createDataChannel(label, init);
// XXX RTP data channels are not defined by the WebRTC standard, have
// been deprecated in Chromium, and Google have decided (in 2015) to no
// longer support them (in the face of multiple reported issues of
// breakages).
int dataChannelId = init.id;
if (-1 != dataChannelId) {
dataChannels.put(dataChannelId, dataChannel);
registerDataChannelObserver(dataChannelId, dataChannel);
}
}
示例8: dataChannelClose
import org.webrtc.DataChannel; //导入依赖的package包/类
void dataChannelClose(int dataChannelId) {
DataChannel dataChannel = dataChannels.get(dataChannelId);
if (dataChannel != null) {
dataChannel.close();
dataChannels.remove(dataChannelId);
} else {
Log.d(TAG, "dataChannelClose() dataChannel is null");
}
}
示例9: onDataChannel
import org.webrtc.DataChannel; //导入依赖的package包/类
@Override
public void onDataChannel(DataChannel dataChannel) {
// XXX Unfortunately, the Java WebRTC API doesn't expose the id
// of the underlying C++/native DataChannel (even though the
// WebRTC standard defines the DataChannel.id property). As a
// workaround, generated an id which will surely not clash with
// the ids of the remotely-opened (and standard-compliant
// locally-opened) DataChannels.
int dataChannelId = -1;
// The RTCDataChannel.id space is limited to unsigned short by
// the standard:
// https://www.w3.org/TR/webrtc/#dom-datachannel-id.
// Additionally, 65535 is reserved due to SCTP INIT and
// INIT-ACK chunks only allowing a maximum of 65535 streams to
// be negotiated (as defined by the WebRTC Data Channel
// Establishment Protocol).
for (int i = 65536; i <= Integer.MAX_VALUE; ++i) {
if (null == dataChannels.get(i, null)) {
dataChannelId = i;
break;
}
}
if (-1 == dataChannelId) {
return;
}
WritableMap dataChannelParams = Arguments.createMap();
dataChannelParams.putInt("id", dataChannelId);
dataChannelParams.putString("label", dataChannel.label());
WritableMap params = Arguments.createMap();
params.putInt("id", id);
params.putMap("dataChannel", dataChannelParams);
dataChannels.put(dataChannelId, dataChannel);
registerDataChannelObserver(dataChannelId, dataChannel);
webRTCModule.sendEvent("peerConnectionDidOpenDataChannel", params);
}
示例10: registerDataChannelObserver
import org.webrtc.DataChannel; //导入依赖的package包/类
private void registerDataChannelObserver(int dcId, DataChannel dataChannel) {
// DataChannel.registerObserver implementation does not allow to
// unregister, so the observer is registered here and is never
// unregistered
dataChannel.registerObserver(
new DataChannelObserver(webRTCModule, id, dcId, dataChannel));
}
示例11: dataChannelStateString
import org.webrtc.DataChannel; //导入依赖的package包/类
@Nullable
private String dataChannelStateString(DataChannel.State dataChannelState) {
switch (dataChannelState) {
case CONNECTING:
return "connecting";
case OPEN:
return "open";
case CLOSING:
return "closing";
case CLOSED:
return "closed";
}
return null;
}
示例12: handleCallConnected
import org.webrtc.DataChannel; //导入依赖的package包/类
private void handleCallConnected(Intent intent) {
if (callState != CallState.STATE_REMOTE_RINGING && callState != CallState.STATE_LOCAL_RINGING) {
Log.w(TAG, "Ignoring call connected for unknown state: " + callState);
return;
}
if (!Util.isEquals(this.callId, getCallId(intent))) {
Log.w(TAG, "Ignoring connected for unknown call id: " + getCallId(intent));
return;
}
if (recipient == null || peerConnection == null || dataChannel == null) {
throw new AssertionError("assert");
}
audioManager.startCommunication(callState == CallState.STATE_REMOTE_RINGING);
bluetoothStateManager.setWantsConnection(true);
callState = CallState.STATE_CONNECTED;
if (localVideoEnabled) lockManager.updatePhoneState(LockManager.PhoneState.IN_VIDEO);
else lockManager.updatePhoneState(LockManager.PhoneState.IN_CALL);
sendMessage(WebRtcViewModel.State.CALL_CONNECTED, recipient, localVideoEnabled, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
unregisterPowerButtonReceiver();
setCallInProgressNotification(TYPE_ESTABLISHED, recipient);
this.peerConnection.setAudioEnabled(microphoneEnabled);
this.peerConnection.setVideoEnabled(localVideoEnabled);
this.dataChannel.send(new DataChannel.Buffer(ByteBuffer.wrap(Data.newBuilder()
.setVideoStreamingStatus(WebRtcDataProtos.VideoStreamingStatus.newBuilder()
.setId(this.callId)
.setEnabled(localVideoEnabled))
.build().toByteArray()), false));
}
示例13: handleLocalHangup
import org.webrtc.DataChannel; //导入依赖的package包/类
private void handleLocalHangup(Intent intent) {
if (this.dataChannel != null && this.recipient != null && this.callId != null) {
this.accountManager.cancelInFlightRequests();
this.messageSender.cancelInFlightRequests();
this.dataChannel.send(new DataChannel.Buffer(ByteBuffer.wrap(Data.newBuilder().setHangup(Hangup.newBuilder().setId(this.callId)).build().toByteArray()), false));
sendMessage(this.recipient, SignalServiceCallMessage.forHangup(new HangupMessage(this.callId)));
sendMessage(WebRtcViewModel.State.CALL_DISCONNECTED, this.recipient, localVideoEnabled, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
}
terminate();
}
示例14: handleSetMuteVideo
import org.webrtc.DataChannel; //导入依赖的package包/类
private void handleSetMuteVideo(Intent intent) {
AudioManager audioManager = ServiceUtil.getAudioManager(this);
boolean muted = intent.getBooleanExtra(EXTRA_MUTE, false);
this.localVideoEnabled = !muted;
if (this.peerConnection != null) {
this.peerConnection.setVideoEnabled(this.localVideoEnabled);
}
if (this.callId != null && this.dataChannel != null) {
this.dataChannel.send(new DataChannel.Buffer(ByteBuffer.wrap(Data.newBuilder()
.setVideoStreamingStatus(WebRtcDataProtos.VideoStreamingStatus.newBuilder()
.setId(this.callId)
.setEnabled(localVideoEnabled))
.build().toByteArray()), false));
}
if (callState == CallState.STATE_CONNECTED) {
if (localVideoEnabled) this.lockManager.updatePhoneState(LockManager.PhoneState.IN_VIDEO);
else this.lockManager.updatePhoneState(LockManager.PhoneState.IN_CALL);
}
if (localVideoEnabled && !audioManager.isSpeakerphoneOn() && !audioManager.isBluetoothScoOn()) {
audioManager.setSpeakerphoneOn(true);
}
sendMessage(viewModelStateFor(callState), this.recipient, localVideoEnabled, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
}
示例15: onDataChannel
import org.webrtc.DataChannel; //导入依赖的package包/类
@Override
public void onDataChannel(DataChannel dataChannel) {
Log.w(TAG, "onDataChannel:" + dataChannel.label());
if (dataChannel.label().equals(DATA_CHANNEL_NAME)) {
this.dataChannel = dataChannel;
this.dataChannel.registerObserver(this);
}
}