package { import flash.display.Sprite; import flash.display.MovieClip; import flash.events.NetStatusEvent; import flash.net.NetConnection; import flash.net.NetStream; import flash.media.Camera; import flash.media.Microphone; import flash.media.Video; import flash.net.Responder; import flash.utils.Timer; import flash.events.TimerEvent; public class conference extends Sprite { // Overall NetConnection for communicating with FMS private var nc:NetConnection; // RTMP URL, same as directory on FMS private var rtmpURL:String = "rtmp://itp-flash.es.its.nyu.edu/sve204/switchingconference/"; // NetStreams for each stream private var netStreamOut:NetStream; private var netStreamIn1:NetStream; // Camera private var camera:Camera; // Microphone private var microphone:Microphone; // Responder (for communicating messages with FMS) private var responder:Responder; // My Video private var videoOut:Video; // Video Components private var videoIn1:Video; // Stream Names private var outStream:String; private var inStream1:String = "live"; public function conference () { trace("running conference"); // Construct NetConnection and connect to server nc = new NetConnection(); nc.connect(rtmpURL); // Add a listener for connection nc.addEventListener (NetStatusEvent.NET_STATUS,connectionHandler); } // Listener for connection private function connectionHandler (e:NetStatusEvent):void { trace("connection handler"); // If we are connected if (e.info.code == "NetConnection.Connect.Success") { // Create a responder to call a method on server and ask what stream we are responder = new Responder(doEverything); // Call the streamSelect function on server with our new responder nc.call ("streamSelect",responder); } else { trace(e.info.code); } } // Gets the results from the server private function doEverything (myStream:String):void { trace(myStream); // SEtup the camera camera = Camera.getCamera(); camera.setQuality(12800, 0); camera.setMode(160,120,10); // setup the microphone microphone = Microphone.getMicrophone(); microphone.rate = 11; // Video components videoOut = new Video(); videoIn1 = new Video(); // Set positions videoOut.x = 0; videoOut.y = 0; videoIn1.x = 320; videoIn1.y = 0; // Add them to the screen addChild(videoOut); addChild(videoIn1); // Publish our stream netStreamOut = new NetStream(nc); netStreamOut.attachAudio(microphone); netStreamOut.attachCamera(camera); netStreamOut.publish(myStream, "live"); trace("publishing " + myStream); // Attach camera to our video videoOut.attachCamera(camera); //Play incoming streamed video netStreamIn1 = new NetStream(nc); videoIn1.attachNetStream(netStreamIn1); trace("Play Live Stream"); netStreamIn1.play(inStream1); } } }