3
我正在創建p2p Cirrus視頻聊天。 我目前的問題是如何自動連接到用戶,它連接到我的流。後,一些谷歌上搜索,我發現我可以用接下來的建設它:Flex,如何從連接到我的流的遠程用戶獲取對等ID?
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,以便將其放入函數中。 我的第二個問題 - 如何做到這一點?我試圖用遠程共享對象來做到這一點,但我不知道這個結構究竟應該如何看待我的情況。
希望有人幫助我解決這個問題。先謝謝你!