Two Way Communication


i trying create simple two-way chat application. using netconnetion, netstream, camera, microphone , video classes. goal capture audio , video input other clients camera can seen , heard.

 

i think may have issue netstream class. have created 2 netstream instances. nsout instance supposed send out stream , ns instance supposed capture incoming stream attached camera , audio objects.

 

when run code unable establish link between users. have tweaking around code hours no avail.

 

can notice doing wrong in code? kind of appreciated.

 

//establishing connection flash media server
var nc:netconnection = new netconnection();

btn_one
.addeventlistener(mouseevent.click, serverstart);

btn_two
.addeventlistener(mouseevent.click, serverstop);

function serverstart(event:mouseevent):void{
    trace
("connecting up...");
    nc
.addeventlistener(netstatusevent.net_status, nethandler);
    nc
.connect("rtmfp://localhost/mycam");
}

function serverstop(event:mouseevent):void{
    trace
("closing");
    nc
.close();
}

function nethandler(event:netstatusevent):void{
   
switch(event.info.code){
       
case "netconnection.connect.success":
        trace("fms connected");
       
break;
       


var ns:netstream = new netstream();
ns
.publish("live", "record");
ns
.attachaudio(mic);
ns
.attachcamera(cam);
ns
.connect(nc);

ns
.addeventlistener(netstatusevent.net_status, nethandler);

var nsout:netstream = new netstream(nc);
nsout
.play("showlive");


vidstream
.attachnetstream(ns);

var ng:netgroup = new netgroup(nc, groupspec.groupspecwithauthorizations());
ng
.addeventlistener(netstatusevent.net_status, nethandler);

   
}
}

var mytextfield:textfield = new textfield();
mytextfield
.selectable = true;
mytextfield
.background = true;
mytextfield
.x = 165;
mytextfield
.y = 354;
mytextfield
.autosize = textfieldautosize.left;
addchild
(mytextfield);

if (!cam) {
                mytextfield
.text = "no camera installed.";

           
}else {
                mytextfield
.text = "waiting connect.";

           
}

var cam:camera = camera.getcamera();
cam
.setmode(350, 150, 15);
cam
.setquality(0, 85);

cam
.addeventlistener(statusevent.status, statushandler);

var vid:video = new video();
vid
.width = cam.width;
vid
.height = cam.height;
vid
.x = 52;
vid
.y = 33;

vid
.attachcamera(cam);
addchild
(vid);

var mytextfield:textfield = new textfield();
mytextfield
.selectable = true;
mytextfield
.background = true;
mytextfield
.x = 165;
mytextfield
.y = 354;
mytextfield
.autosize = textfieldautosize.left;
addchild
(mytextfield);

if (!cam) {
                mytextfield
.text = "no camera installed.";

           
}else {
                mytextfield
.text = "waiting connect.";

           
}


var mic:microphone = microphone.getenhancedmicrophone();
mic
.framesperpacket = 1;
mic
.setsilencelevel(0, 2000);
mic
.gain = 50;
mic
.codec = soundcodec.speex;

mic
.addeventlistener(statusevent.status, micstatus);

var vidstream:video = new video();
vidstream
.width = cam.width;
vidstream
.height = cam.height;
vidstream
.x =x=(vid.x+ cam.width +10); vidstream.y=vid.y;
addchild
(vidstream);


below excerpt book (flash game development  ) wrote,

 

since flash player 10, can create multiplayer games without need of intermediary server facilitate player communication.  flash player can use protocol (adobe's real-time media flow protocol) allows direct peer-to-peer communication.

 

instead of using server-side code handle game logic , coordinate game state among players, each peer in network handles own game logic , game state , communicates directly peers , each peer updates game state based on data received others.

 

to use peer-to-peer networking each peer must connect adobe server.  peer-to-peer communication not go through server (or not peer-to-peer) peers must stay connected adobe server in order communicate each other.

 

to communicate adobe server should use own server url , developer key. url , key can obtained @ http://www.adobe.com/cfusion/entitlement/index.cfm?e=cirrus.



More discussions in ActionScript 3


adobe

Comments

Popular posts from this blog

Some mp4 files not displaying correctly (CS6)

Thread: Samba is not authenticating with LDAP