当前位置: 首页>>代码示例>>Java>>正文


Java DataChannel.Buffer方法代码示例

本文整理汇总了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");
    }
}
 
开发者ID:angellsl10,项目名称:react-native-webrtc,代码行数:25,代码来源:PeerConnectionObserver.java

示例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);
}
 
开发者ID:angellsl10,项目名称:react-native-webrtc,代码行数:25,代码来源:DataChannelObserver.java

示例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");
    }
}
 
开发者ID:respoke,项目名称:respoke-sdk-android,代码行数:30,代码来源:RespokeDirectConnection.java

示例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);
}
 
开发者ID:nubomedia-vtt,项目名称:nubo-test,代码行数:9,代码来源:PeerVideoActivity.java

示例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);
    }
}
 
开发者ID:nubomedia-vtt,项目名称:webrtcpeer-android,代码行数:8,代码来源:NBMPeerConnection.java

示例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);
}
 
开发者ID:nubomedia-vtt,项目名称:nubo-test,代码行数:6,代码来源:PeerVideoActivity.java

示例7: onMessage

import org.webrtc.DataChannel; //导入方法依赖的package包/类
@Override
public void onMessage(DataChannel.Buffer buffer) {
    System.out.println("DEBUG: message received " + buffer.data);

}
 
开发者ID:getlantern,项目名称:webrtc-java,代码行数:6,代码来源:Observer.java

示例8: onMessage

import org.webrtc.DataChannel; //导入方法依赖的package包/类
@Override
public void onMessage(DataChannel.Buffer buffer, NBMPeerConnection connection, DataChannel channel) {

}
 
开发者ID:nubomedia-vtt,项目名称:nubo-test-tree,代码行数:5,代码来源:MasterVideoActivity.java

示例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);
 
开发者ID:nubomedia-vtt,项目名称:webrtcpeer-android,代码行数:8,代码来源:NBMWebRTCPeer.java


注:本文中的org.webrtc.DataChannel.Buffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。