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 (将#修改为@)