Rewrite flex code based on nginx-rtmp module examples.