Форум Flasher.ru

Форум Flasher.ru (http://www.flasher.ru/forum/index.php)
-   Серверные технологии и Flash (http://www.flasher.ru/forum/forumdisplay.php?f=62)
-   -   как определить, есть ли соединение с сервером red5 (http://www.flasher.ru/forum/showthread.php?t=139860)

smailik 13.05.2010 11:16

как определить, есть ли соединение с сервером red5
 
Вообщем в red5 есть уроки, и среди них есть простенький рекордер (записывает данные с веб- камры на сервер)
Код AS1/AS2:

/*
Author: John Grden
email: neoRiley@gmail.com
 
This sample is a basic recorder.  It saves the stream to the webapps/oflaDemo/streams folder and plays
it back once you click the stop button.
*/

 
import mx.utils.Delegate;
 
// create basic netConnection object
var nc:NetConnection = new NetConnection();
 
// connect to the local Red5 server
nc.connect("rtmp://172.20.1.55/oflaDemo");
 
// create the netStream object and pass the netConnection object in the constructor
var ns:NetStream = new NetStream(nc);
 
// get references to the camera and mic
var cam:Camera = Camera.get();
var mic:Microphone = Microphone.get();
 
// setup some simple settings with the cam and mic for quality
setupCameraMic();
 
// we store the last saved recording so we can play it back when stop is clicked
var lastVideoName:String = "";
 
// listen for the button clicks
/*playButton.addEventListener("click", Delegate.create(this, playClick));
stopButton.addEventListener("click", Delegate.create(this, stopClick));
*/

 
function playClick():Void
{
        // This FLV is recorded to webapps/oflaDemo/streams/ directory
        // attach cam and mic to the NetStream Object
        ns.attachVideo(cam);
        ns.attachAudio(mic);
 
        // attach the cam to the videoContainer on stage so we can see ourselves
        videoContainer.attachVideo(cam);
 
        // create a random number to store a unique name
        var today_date:Date = new Date();
        var date_str:String = (today_date.getDate()+"_"+(today_date.getMonth()+1)+"_"+today_date.getFullYear()+"_"+today_date.getHours()+"_"+today_date.getMinutes()+"_"+today_date.getSeconds());
        //lastVideoName = "2red5RecordDemo_" + random(getTimer());
        ns.publish(_root.file + "_"+date_str, "record");
 
}
 
function stopClick():Void
{
        // close the netStream object
        ns.close();
 
        // clear the videoContainer
        videoContainer.attachVideo(null);
        videoContainer.clear();
 
        // enable the playbutton
        playButton.enabled = true;
 
        // disable the stop button
        stopButton.enabled = false;
 
        // play the recording back
        //playLastVideo();
}
 
function playLastVideo():Void
{
        // attach the netStream object to the video object
        videoContainer.attachVideo(ns);
 
        // play back the recorded stream
        ns.play(lastVideoName);
}
 
function setupCameraMic():Void
{
        // setup cam
        cam = Camera.get();
        // setting dimensions and framerate
        cam.setMode(320, 240, 30);
        // set to minimum of 70% quality
        cam.setQuality(0,70);
 
        // setup mic
        mic = Microphone.get();
        mic.setRate(44);
}
playClick ();

Нужно сделать проверку соединения с сервером раз в минуту, и в случае отсутствия соединения, вызвать фнкцию.
Проблема встала в том, что я не знаю как определять статус соединения.

Добавлено через 39 минут
Код AS1/AS2:

nc.onStatus = function(info){
        trace ("ok");
    if (info.code == "NetConnection.Connect.Success") {
        trace ("connect");
    }    else {
        if (! nc.isConnected){
            trace("not Connect");
        }
    }
};

вот что нашел, но вот не могу вызывать это, по нажатию кнопки =(

Taller 14.05.2010 09:38

При обрыве связи будет сгенерирован exception. При нажатии кнопки просто все соединения должны вызвать метод close.

Вроде так.
Следите за логом red5


Часовой пояс GMT +4, время: 18:51.

Copyright © 1999-2008 Flasher.ru. All rights reserved.
Работает на vBulletin®. Copyright ©2000 - 2026, Jelsoft Enterprises Ltd. Перевод: zCarot
Администрация сайта не несёт ответственности за любую предоставленную посетителями информацию. Подробнее см. Правила.