Added: No Camera Detected imagery

This commit is contained in:
Tom Moor 2013-02-27 11:18:59 -08:00
parent a0188d698e
commit 3bccb318ae
2 changed files with 1 additions and 1 deletions

@ -1 +1 @@
package com.sqwiggle { import flash.events.NetStatusEvent; import flash.media.Camera; import flash.net.NetConnection; import flash.net.NetStream; import flash.media.Microphone; import flash.media.SoundCodec; import flash.events.MouseEvent; import flash.events.Event; import fl.transitions.Tween; import fl.transitions.easing.*; import com.sqwiggle.Member; public class Self extends Member { var cam:Camera; var mic:Microphone; public function Self(userId:String) { super(userId, '', 'Me'); // TODO: check for camera cam = Camera.getCamera(); cam.setQuality(0, 100); cam.setMode(160,120, 1); // TODO: check for mic mic = Microphone.getMicrophone(); mic.enableVAD = true; mic.codec = SoundCodec.SPEEX; mic.encodeQuality = 10; mic.setSilenceLevel(100); mic.setUseEchoSuppression(true); } public function updatePeerId():void { var options = new Object(); options.peer_id = peerId; // make an API request to save the new peerID var request = Api.putRequest('/users/update', options); // dispatch an event once the peerID is updated request.addEventListener(Event.COMPLETE, function(event:Event) { dispatchEvent(new Event("Connected")); }); } protected override function updateActivity(event:Event):void { if (mic) { activity.alpha = 100 / (50 + (mic.activityLevel/2)); } } public override function connectToVideo(connection:NetConnection):void { peerId = connection.nearID; Sqwiggle.trace('Publishing video to: ' + userId + ', stream: ' + peerId); stream = new NetStream(connection, NetStream.DIRECT_CONNECTIONS); stream.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus); stream.attachCamera(this.cam); stream.publish(this.userId); var client:Object = new Object(); client.onPeerConnect = function(caller:NetStream):Boolean { Sqwiggle.trace('Member connecting to your video stream: ' + caller.farID); return true; }; stream.client = client; video.attachCamera(this.cam); video.smoothing = true; video.deblocking = 5; // ensure we update this users peerID on the server for // other clients to connect to. updatePeerId(); } public override function audioOn(conversationInProgress:Boolean=false):void { mic.setSilenceLevel(0); stream.attachAudio(mic); activity.visible = true; if (conversationInProgress) { new Tween(video, "alpha", Regular.easeIn, 1, alpha, 0.5, true); } Sqwiggle.trace('Your audio is now on'); } public override function audioOff(conversationInProgress:Boolean=false):void { mic.setSilenceLevel(100); stream.attachAudio(null); activity.visible = false; if (conversationInProgress) { new Tween(video, "alpha", Regular.easeIn, 1, alpha, 1, true); } Sqwiggle.trace('Your audio is now off'); } } }
package com.sqwiggle { import flash.events.NetStatusEvent; import flash.media.Camera; import flash.net.NetConnection; import flash.net.NetStream; import flash.media.Microphone; import flash.media.SoundCodec; import flash.events.MouseEvent; import flash.events.Event; import fl.transitions.Tween; import fl.transitions.easing.*; import com.sqwiggle.Member; public class Self extends Member { var cam:Camera; var mic:Microphone; var noc; public function Self(userId:String) { cam = Camera.getCamera(); mic = Microphone.getMicrophone(); if (cam) { cam.setQuality(0, 100); cam.setMode(160,120, 1); } if (mic) { mic.enableVAD = true; mic.codec = SoundCodec.SPEEX; mic.encodeQuality = 10; mic.setSilenceLevel(100); mic.setUseEchoSuppression(true); } super(userId, '', 'Me'); } public override function render(w:Number, h:Number):void { super.render(w, h); if (!cam) { w = Math.min(Member.MAX_WIDTH, w); h = Math.min(Member.MAX_HEIGHT, h); noc = new NoCameraDetected(); noc.x = w/2; noc.y = h/2; noc.visible = true; addChild(noc); } } public function updatePeerId():void { var options = new Object(); options.peer_id = peerId; // make an API request to save the new peerID var request = Api.putRequest('/users/update', options); // dispatch an event once the peerID is updated request.addEventListener(Event.COMPLETE, function(event:Event) { dispatchEvent(new Event("Connected")); }); } protected override function updateActivity(event:Event):void { if (mic) { activity.alpha = 100 / (50 + (mic.activityLevel/2)); } } public override function connectToVideo(connection:NetConnection):void { peerId = connection.nearID; Sqwiggle.trace('Publishing video to: ' + userId + ', stream: ' + peerId); stream = new NetStream(connection, NetStream.DIRECT_CONNECTIONS); stream.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus); stream.attachCamera(this.cam); stream.publish(this.userId); var client:Object = new Object(); client.onPeerConnect = function(caller:NetStream):Boolean { Sqwiggle.trace('Member connecting to your video stream: ' + caller.farID); return true; }; stream.client = client; video.attachCamera(this.cam); video.smoothing = true; video.deblocking = 5; // ensure we update this users peerID on the server for // other clients to connect to. updatePeerId(); } public override function audioOn(conversationInProgress:Boolean=false):void { mic.setSilenceLevel(0); stream.attachAudio(mic); activity.visible = true; if (conversationInProgress) { new Tween(video, "alpha", Regular.easeIn, 1, alpha, 0.5, true); } Sqwiggle.trace('Your audio is now on'); } public override function audioOff(conversationInProgress:Boolean=false):void { mic.setSilenceLevel(100); stream.attachAudio(null); activity.visible = false; if (conversationInProgress) { new Tween(video, "alpha", Regular.easeIn, 1, alpha, 1, true); } Sqwiggle.trace('Your audio is now off'); } } }

BIN
p2p.fla

Binary file not shown.