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; 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.nyu.edu/sve204/conference"; // NetStreams for each stream private var netStreamOut:NetStream; private var netStreamIn1:NetStream; private var netStreamIn2:NetStream; private var netStreamIn3: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; private var videoIn2:Video; private var videoIn3:Video; // Stream Names private var outStream:String; private var inStream1:String; private var inStream2:String; private var inStream3:String; public function 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 { // 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); } } // Gets the results from the server private function doEverything (myStream:String):void { // SEtup the camera camera = Camera.getCamera(); // setup the microphone microphone = Microphone.getMicrophone(); // Video components videoOut = new Video(); videoIn1 = new Video(); videoIn2 = new Video(); videoIn3 = new Video(); // Set positions videoOut.x = 0; videoOut.y = 0; videoIn1.x = 320; videoIn1.y = 0; videoIn2.x = 0; videoIn2.y = 240; videoIn3.x = 320; videoIn3.y = 240; // Add them to the screen addChild(videoOut); addChild(videoIn1); addChild(videoIn2); addChild(videoIn3); // Set the stream names switch (myStream) { case "one" : outStream="one"; inStream1="two"; inStream2="three"; inStream3="four"; break; case "two" : outStream="two"; inStream1="one"; inStream2="three"; inStream3="four"; break; case "three" : outStream="three"; inStream1="one"; inStream2="two"; inStream3="four"; break; case "four" : outStream="four"; inStream1="one"; inStream2="two"; inStream3="three"; break; } // Publish our stream netStreamOut = new NetStream(nc); netStreamOut.attachAudio(microphone); netStreamOut.attachCamera(camera); netStreamOut.publish(outStream, "live"); // Attach camera to our video videoOut.attachCamera(camera); //Play incoming streamed video netStreamIn1 = new NetStream(nc); netStreamIn2 = new NetStream(nc); netStreamIn3 = new NetStream(nc); videoIn1.attachNetStream(netStreamIn1); videoIn2.attachNetStream(netStreamIn2); videoIn3.attachNetStream(netStreamIn3); netStreamIn1.play(inStream1); netStreamIn2.play(inStream1); netStreamIn3.play(inStream1); } } }