Home | Search | Login | RSS
We have 1073 members and counting!
Next Page

1

Previous Page

Thread: Accessing camera from lan and internet

Created on: 03/13/09 12:34 PM

Replies: 0

leecld





Joined: 03/13/09

Posts: 1

Accessing camera from lan and internet
03/13/09 12:34 PM

Is it possible to access a webcam from lan and from internet at the same time?
I have FMS3 setup on a local ip address with the router forwarding ports to it. But once a request comes in off the internet, they need to be sent out with the routers ip address. Here is an example. If I wanted to access the camera from my lan, I would have the swf point to a local ip address. but if I wanted to access the camera from the internet, I would need to use the router's ip address in the swf otherwise the page I am looking at would try to find the Flash Media Server on that local network. So I found some code that I modified in order to do this in the swf. But am I doing it the hard way. Could I just tell the FMS to interpret forward that come from internet to go out as a different IP address?
Here is what I did with the swf in order to view camera from lan and internet at the same time. I had to put an extra case in for it to actually work.


var nc:NetConnection = new NetConnection();
var ncConnectTimer:Number = 0;
var ncConnectTimeout:Number = 5000; // 5 seconds
var ncTryIndex:Number = 0;
var cam:Camera;
var ns:NetStream;
var nsPlayer:NetStream;

function init()
{
nc.onStatus = function(info:Object)
{
trace(info.code);
if(info.code.indexOf("Success") !=-1)
{
clearConnectTimer();
}
else if(info.code == "NetConnection.Connect.Failed")
tryReconnect();
}
}

function clearConnectTimer()
{
if (ncConnectTimer != 0)
clearInterval(ncConnectTimer);
ncConnectTimer = 0;
}

function tryConnect()
{
clearConnectTimer();

var url:String = "";
switch(ncTryIndex)
{
case 0:
url = "rtmp://x.x.x.207/live/_definst_";
break;
case 1:
url = "rtmp://192.168.1.1/live/_definst_";
break;
case 2:
url = "rtmp://192.168.1.76/live/_definst_";
break;
default:
trace("Failed to connect after "+ncTryIndex+" tries");
break;
}

if (url.length > 0)
{
nc.connect(url);
ncConnectTimer = setInterval(_root, "tryReconnect", ncConnectTimeout);
getCam();
}
}

function tryReconnect()
{
trace("tryReconnect");
clearConnectTimer();
ncTryIndex++;
tryConnect();
}

function getCam()
{
cam = Camera.get();
cam.setMode(320, 240, 10);
cam.setQuality(0, 85);
ns = new NetStream(nc);
ns.attachVideo(cam);
ns.publish("mycam", "live");

//make the player stream too
nsPlayer = new NetStream(nc);
nsPlayer.play("mycam");
vid.attachVideo(nsPlayer);
}

init();
tryConnect();

Link | Top | Bottom

Next Page

1

Previous Page

New Post

Please login to post a response.