如何解决android janus webrtc ondatachannel未触发
我已经让 Janus videoroom 正常工作,现在我想实现 DataChannel 在设备之间相互发送消息
当发布者发送配置和订阅者加入时,我已经设置了 data:true
void sendLocalDescription(BigInteger handleId,JSONObject sdpObj) {
try {
JSONObject msg = new JSONObject();
JSONObject body = new JSONObject();
body.put(REQUEST,BodyRequestMessageType.CONfigURE.getType());
body.put(AUdio,options.audio);
body.put(VIDEO,options.video);
body.put(DATA,true);
msg.put(JANUS,SendMessageType.MESSAGE.getType());
msg.put(TRANSACTION,RandomUtil.randomString());
msg.put(SESSION_ID,sessionId);
msg.put(HANDLE_ID,handleId);
msg.put(BODY,body);
msg.put(JESP,sdpObj);
connection.sendMessage(msg.toString());
Log.e(SERVER_TAG,"publisher sendLocalDescription: " + body.toString());
} catch (JSONException e) {
e.printstacktrace();
}
}
这里是给订阅者的
private void sendSubscribeMessage() {
try {
JSONObject object = new JSONObject();
object.put(JANUS,SendMessageType.MESSAGE.getType());
object.put(PLUGIN,PLUGIN_VALUE);
object.put(TRANSACTION,RandomUtil.randomString());
object.put(SESSION_ID,sessionId);
object.put(HANDLE_ID,handleId);
JSONObject body = new JSONObject();
body.put(REQUEST,BodyRequestMessageType.JOIN.getType());
body.put(PTYPE,PType.SUBSCRIBER.getType());
body.put(ROOM,options.meetNum);
body.put(PIN,options.pin);
body.put(PRIVATE_ID,privateId);
body.put(Feed,publisherBean.getId());
body.put(DATA,true);
body.put(OFFER_DATA,true);
object.put(BODY,body);
connection.sendMessage(object.toString());
if(publisherBean.isSumulcast()){
sendConfigureSimulcastMessage();
}
} catch (JSONException e) {
e.printstacktrace();
}
}
为发布者创建对等连接后,我创建了数据通道:
peerConnection = PCFactoryProxy.instance().createPeerConnection(configuration,this);
dataChannel = peerConnection.createDataChannel("1",new DataChannel.Init());
dataChannel.registerObserver(new DataChannel.Observer() {
@Override
public void onBufferedamountChange(long l) {
}
@Override
public void onStateChange() {
Log.e(SERVER_TAG,"dataChannel state: " + dataChannel.state().toString());
}
@Override
public void onMessage(DataChannel.Buffer buffer) {
}
});
但我从未看到 onDataChannel 被触发,有人可以帮忙吗?
@Override
public void onDataChannel(DataChannel dataChannel) {
LogUtil.e(SERVER_TAG,"PeerConnectionChannelV3 -> onDataChannel: " + dataChannel.label());
this.dataChannel = dataChannel;
// this.dataChannel.registerObserver(this);
// sendDataChannelMessage("test");
}
据我所知 DataChannel,当 Peer A 已经有数据通道对象时,Peer B 会在 onDataChannel 被触发时接收数据通道
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。