我正在创建一个p2p Cirrus视频聊天我目前的问题是如何自动连接到连接到我的流的订阅者在谷歌上搜索后,我发现我可以使用下一个结构:
var clientObject:Object = new Object();
clientObject.onPeerConnect = function(callerns:NetStream):Boolean{
return true;
}
我的流:
发送流:
private function initSendNetStream():void{
trace("initSendStream");
sendStream = new NetStream(nc,NetStream.DIRECT_CONNECTIONS);
sendStream.addEventListener(NetStatusEvent.NET_STATUS, netStatusEvent);
var clientObject:Object = new Object();
clientObject.onPeerConnect = function(callerns:NetStream):Boolean{
return true;
}
sendStream.client = clientObject;
sendStream.attachCamera(cam);
sendStream.attachAudio(mic);
sendStream.publish('video');
log('Net Stream publish start');
}
和接收流:
private function addContact(peerID:String):void {
var nc2:NetConnection = new NetConnection();
nc2.addEventListener(NetStatusEvent.NET_STATUS, function (event:NetStatusEvent):void {
trace('NetConnection status event (2): ' + event.info.code);
var receiveNS:NetStream = new NetStream(nc2, /*ContactPeerID.text*/ peerID);
receiveNS.addEventListener(NetStatusEvent.NET_STATUS, netStatusEvent);
receiveNS.play('video');
var video:Video = new Video();
video.attachNetStream(receiveNS);
var uic:UIComponent = new UIComponent();
uic.width = 320;
uic.height = 240;
uic.addChild(video);
uic.toolTip = txtData.selectedItem.name;
VideoStack.addChild(uic);
//Clean ContactPeerID form
ContactPeerID.text = '';
});
nc2.connect(SERVER_ADDRESS+DEVELOPER_KEY);
}
我的想法是在这个结构中添加联系人功能:
var clientObject:Object = new Object();
clientObject.onPeerConnect = function(callerns:NetStream):Boolean{
return true;
}
然而,为了做到这一点,我应该检测并接收订阅者的ID,将其放入函数中我的第二个问题-怎么做我正试图用远程共享对象来实现这一点,但我不知道这个结构在我的情况下应该是什么样子。
希望有人帮我解决这些问题。提前谢谢!
我不确定您要实现什么p2p连接架构。但为了找出连接的对等体的ID,你可以试试这个:
callerns.farID
onPeerConnect函数内部。