本文整理汇总了Java中org.webrtc.DataChannel.Buffer方法的典型用法代码示例。如果您正苦于以下问题:Java DataChannel.Buffer方法的具体用法?Java DataChannel.Buffer怎么用?Java DataChannel.Buffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.webrtc.DataChannel
的用法示例。
在下文中一共展示了DataChannel.Buffer方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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");
}
}
示例4: sendHelloMessage
import org.webrtc.DataChannel; //导入方法依赖的package包/类
public void sendHelloMessage(DataChannel channel) {
byte[] rawMessage = "Hello Peer!".getBytes(Charset.forName("UTF-8"));
ByteBuffer directData = ByteBuffer.allocateDirect(rawMessage.length);
directData.put(rawMessage);
directData.flip();
DataChannel.Buffer data = new DataChannel.Buffer(directData, false);
channel.send(data);
}
示例5: onMessage
import org.webrtc.DataChannel; //导入方法依赖的package包/类
@Override
public void onMessage(DataChannel.Buffer buffer) {
Log.i(TAG, "[ObservedDataChannel] NBMPeerConnection onMessage");
for (NBMWebRTCPeer.Observer observer : observers) {
observer.onMessage(buffer, NBMPeerConnection.this, channel);
}
}
示例6: onMessage
import org.webrtc.DataChannel; //导入方法依赖的package包/类
@Override
public void onMessage(DataChannel.Buffer buffer, NBMPeerConnection connection, DataChannel channel) {
Log.i(TAG, "[datachannel] Message received: " + buffer.toString());
sendHelloMessage(channel);
}
示例7: onMessage
import org.webrtc.DataChannel; //导入方法依赖的package包/类
@Override
public void onMessage(DataChannel.Buffer buffer) {
System.out.println("DEBUG: message received " + buffer.data);
}
示例8: onMessage
import org.webrtc.DataChannel; //导入方法依赖的package包/类
@Override
public void onMessage(DataChannel.Buffer buffer, NBMPeerConnection connection, DataChannel channel) {
}
示例9: onMessage
import org.webrtc.DataChannel; //导入方法依赖的package包/类
/**
* WebRTC event which is triggered when a message is received from a data channel
* @param buffer The message buffer
* @param connection The connection for which the data channel belongs to
* @param channel The data channel which triggered the event
*/
void onMessage(DataChannel.Buffer buffer, NBMPeerConnection connection, DataChannel channel);