March 25, 2007

Ask an FMS Guru #20: How do I tell a user why their connection request was rejected?

Oh good, an easy one :). Got a question asker here asking how it would be to tell a user why they were rejected from connecting to the application.

The question: How do I tell a user why their connection request was rejected?

The answer:

So, the deal is that you have an application with a bit of security on it. Which is of course always a good idea because you never know when a malicious user is going to come along and create some huge FLV files or something on your server.

For example, say you stopped users if they didn't pass in a username when connecting to the server. On the server side you might write something like this:

application.onConnect = function(clientObj, userName){
//no userName value passed in? or an empty string?
if(userName == undefined || userName == ""){
application.rejectConnection(clientObj);
}else{
//looks good, they have passed something in
application.acceptConnection(clientObj);
}
}

Now, that isn't so robust and is relatively easy to get around.. but makes for a simple example on how to accept or reject a connection based on certain circumstances.

In the above case the user will get rejected and you can handle that event on the client side with the onReject event that gets passed back to the netConnection object, but you don't know why you were rejected. In our coding, we only have one reason why somebody would get rejected so it's easy to tell, but what if there were a bunch of options? Like maybe, the user is a banned user, or their password was wrong, or it's too early etc.

To pass back some information you would create an object that can hold the error message and pass that in the rejectConnection method. Something like this:

var errorObj = new Object();
//pass back a message of what is wrong
errorObj.msg = "Password is wrong";
//or even just pass back a predetermined code number that you think of
errorObj.code = 1;
application.rejectConnection(clientObj, errorObj);

Then, on the client side you could catch that like so:

nc.onStatus = function(info){
var code = info.code;
if(code == "NetConnection.Connect.Reject"){
//trace out the string message that was set
trace(info.application.msg);
//trace out the preset code that that was set
trace(info.application.code);

}
}

So, based on the information that you can get out of the information object in the onStatus event, you can now tell why you were rejected and incorporate that into the application by maybe retrying to a different server, or showing the password screen again or letting the user know they are banned, or whatever :)

Posted by Graeme at 08:40 AM | Comments (0)

March 23, 2007

Apollo Tip: How to not have the Apollo window controls show up

hmph, it happens almost every time.. You mess with something new, can't figure it out, ask somebody or at somewhere and 5 minutes later.. you've figured it out.

Anyhow, just in case this helps somebody else:

Quick tip on making sure that there are no window controls in your Apollo application.

First thing is to edit your application XML file in the rootContent tag to have the following:

systemChrome="none" transparent="true" visible="true"

Then, and this is key and where I messed up, make sure that your Application tag is not set to mx:ApolloApplication but is instead just set to the normal mx:Application. You then must place in some buttons that will close/minimize the application.

The close function must call this:
stage.window.close();

The minimize function must call this:
stage.window.minimize();

That's it!

Here's a screen shot of mine:

Posted by Graeme at 10:47 AM | Comments (0)

In Apollo, how do you get rid of the Apollo window controls?

I can't figure out for the life of me how the weather app got rid of the controls for the window. As in, the little close and minimize buttons.

I'm working on a small application and I just want it to act like a little widget of some sorts where the whole background is slightly transparent and the content is visible inside that. Then in the corner I would have my own minimize and close buttons.

I've tried everything (I think) and just can't get it to work like I want it. The application always shows the Apollo controls.

I have my application XML file with this in it:
systemChrome="none" transparent="true" visible="true"

and this in my MX:Styles
Application
{
background-color:"";
background-image:"";
padding: 0px;
background-alpha:"0.4";
}

but no go.

I've searched the Apollo forums but it doesn't seem like anybody else has come across this. Any advice?

Posted by Graeme at 09:58 AM | Comments (5)

I wish I was at WebDU2007..

I was just watching the video before the keynote for WebDU2007 in Australia and I felt this pang of .... hmm.. regret I think, that made we wish I had gone to the conference.

I've been there the last two years talking about video and also Flash Media Server, but this year is just too busy for me to get away for a week. I mean.. I suppose I could have, but not without being hunted down later and assassinated in some way.

MXDU2005 and WebDU2006 were awesome and I've always said that Geoff and company put on the best conference in the world and the people I meet each and every time are great. Combined with that Australia is a really cool place to go.

*sniff*..

Next year I'll go.

Now I know why Jesse is back there. I met him in 2005 and hassled him in 2006 to go but he said that conferences might not be worth the investment. He's there this year though ;)

Posted by Graeme at 06:45 AM | Comments (1)

March 21, 2007

My first impression of Apollo

Well, it's not like I have a lot of time on my hands but I thought I'd give Apollo a whirl and see how it goes. There's a lot of hype going on at the moment about it and I'm pretty curious to see how it stands up to other swf to exe apps.

Creating apps for Apollo is simple if you already have experience with Flex, which I do. So getting into the application making is a snap. I do have to say that it took me a good 10 minutes to get the icons for the application I made to show up.. Not for any fault of Adobe but my own for not noticing that the tags for the icons were sitting inside a comment block.. duh

Anyhow, once I got over that little hurdle I started to look at the rest a bit and see that the background that Flex puts in is not supported by Apollo. Or something like that because my app has a drab grey background to it when installed. All I made was a basic video player and then just embedded the FLV files in the AIR file. Worked fine.

Something I would like to see in the future would be an uninstall file in the install directory so I don't have to go to the control panel and find it in the programs list to uninstall. I'm on windows, not a mac so I can't just go and delete the directory.

I haven't had any experience yet in trying to get the file object to work or find out how on and off connectivity go, I'll see what I can do tomorrow or the next day. It looks good though, simple to create AIR files and then install. Looking forward to spending a bit more time with Apollo in the near future.

Posted by Graeme at 04:38 PM | Comments (1)

March 16, 2007

Ask an FMS Guru #19: I want to serve multiple FLV files from FMS2. Can this be done in a simple way?

Streaming video from FMS is probably one of the most common uses of the software. Here is a common question that I've seen:

The question: I want to serve multiple FLV files from FMS2. Can this be done in a simple way?

The answer:

A bit of background just in case.

There are two ways to stream FLV files at the moment. You can serve them from a web server (and there are a couple of ways to do this) or you can serve them from an FLV streaming server which in our case is Flash Media Server 2.0.4. Currently there are two other pieces of software out there that can stream FLV files. Red 5, which is an open source option, and Wowza which is a commercial product that works somewhat like FMS.

The difference between serving the files progressively (web server) and streaming is mainly that the file doesn't get cached on the client's computer and in theory is served faster to the client. There is a lot more information on the internet on this, so that's all I'll cover for now.

So, the idea is that we are going to use Flash and Flash Media Server to stream an FLV or multiple FLV files to our clients.

First up, let's get FMS ready to stream a file.

When installing FMS you will get a directory called "applications". It usually resides in the installation directory of FMS, but you can put it anywhere, and in fact are encouraged to move it elsewhere. But this isn't a chat on security or performance so I'll stay away from that for the time being.

In the applications directory, let's make a folder called "videostreaming". This is necessary to have clients connect up to the server itself and also a place to put our video files. Now it's important to note that you can put your videos in a central location, or multiple locations and specify those locations as virtual folders for FMS. That lets you keep videos in certain places on your server and access them from different applications. Handy.

So, we have the folder in the applications directory "videostreaming". In there, let's make a directory called "myvideos" and in there create another folder called "streams".

So:
applications-|
--------------videostreaming-|
--------------------------------myvideos-|
--------------------------------------------streams

In there, we put our video file. For this example we'll use the video file name of "video1.flv".

We have now setup FMS, let's move to Flash to build the client side.

To do this the most simple way I won't be covering controls for the video. Just how to start playing the FLV file.

Open up a new file in Flash and select the first frame and open up the actions panel.

We start off by creating a net connection to the server and then we'll watch to see when we connect up. Once connected up we will create a stream object and then play the FLV file. Playing the FLV file and showing it actually requires we make a video object, so we'll do that after the actionscript.

//create a netConnection object
var nc = new NetConnection();

//keep an eye on the status events, we need to know when we have connected up
nc.onStatus = function(info){
if(info.code == "NetConnection.Connect.Success"){
createStreamObject();
}
}

//this function is called once we have connected up to the server
function createStreamObject(){
//this is the netStream object that plays the video file
ns = new NetStream(nc);
//attach the video stream to the video object on the stage
vidObject.attachVideo(ns);
//play the video file that we put in the directory for the application
ns.play("video1");
}

//connect up
nc.connect("rtmp://MYSERVERIP/videostreaming/myvideos");

As you can see above, we are connecting to a server with the application name of "videostreaming" and the instance name is "myvideos". We put that in because that is the folder hierarchy that we created on Flash Media Server.

All that is left is to create a new layer in the timeline and make a new video object from the library panel menu. Place that on that layer on the stage and call the instance name "vidObject".

That's it! Run the file and you should have a video playing on the stage.

If it doesn't work, you need to find out if you are even connecting up to the server. That would require opening up the FMS admin panel and seeing if there are connections being made, and if there are then double check the filename and mistyping.

That is the most simplistic way to stream an FLV file. There is also the option to use the FLVPlayer component, that's a pretty good option too I think.

Posted by Graeme at 10:19 AM | Comments (6)

March 11, 2007

Email senders can also fight spam

I found this article a few days back and kept meaning to post it here because there are some good points here that I constantly think of when I'm sending email.

Here is the article: How the Sender Community Can Help Fight Spam.

On that subject, I also had quite a few clients that will send emails with no subject in the email, or something completely different than the contents of the email. For example, "Hi Graeme!!" or "Another email from me!" or "FYI". Which is completely non-descriptive of the email content. It's frustrating and I always will then just politely ask that they send emails with subjects that are pertinent to the information in the actual email. It's one person at a time, but it works and once explained once people get it.

Due to the amount of spam that comes through, it's getting a bit harder and harder to filter out the garbage and keep the good stuff when the sender doesn't make a bigger effort to not be caught by the filters. Ironically enough, it's the spammers that are making the biggest effort to not get caught by the filters..

So, if you have clients or friends that constantly write odd subject headers in emails, or often forget to even put one in, perhaps send them to that article. It covers some good points I think.

Posted by Graeme at 06:16 AM | Comments (0)