Flex,如何从连接到我的流的远程用户获取对等 ID?
我正在创建 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 以将其放入函数中。 我的第二个问题 - 如何做到这一点? 我正在尝试使用远程共享对象来做到这一点,但我不知道这个结构在我的情况下应该是什么样子。
希望有人帮助我解决这个问题。先感谢您!
I'm creating a p2p Cirrus video chat. My current problem is how to automatically connected to subscriber, which connected to my stream. After some googling I found that I can do it using next construction:
var clientObject:Object = new Object();
clientObject.onPeerConnect = function(callerns:NetStream):Boolean{
return true;
}
My streams:
Send stream:
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');
}
and Receive stream:
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);
}
My idea is just put add contact function inside this construction:
var clientObject:Object = new Object();
clientObject.onPeerConnect = function(callerns:NetStream):Boolean{
return true;
}
However, for doing this I should detect and receive ID of subscriber to put it in a function. My second problem- how to do that? I'm trying to do it with remote Shared Object, but I don't know exactly how this structure should look in my case.
Hope someone help my with this questions. Thank you in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定您要实现什么 p2p 连接架构。
但为了找出连接的对等点的 ID,您可以尝试以下操作:
在 onPeerConnect 函数内。
I'm not sure what p2p connection architecture you're going to implement.
But just to find out the ID of the connected peer, you may try this:
inside the onPeerConnect function.