After Some Weeks Server's Some Services halted Or Memory Full

Hi,

We have noticed that after some weeks some services halted or memory is full. Due to which publishing videos failed and we have to restart the server and service.
How we can fix this problem.

Please see our working code below.
Code:
var SESSION_STATUS = Flashphoner.constants.SESSION_STATUS;
var STREAM_STATUS = Flashphoner.constants.STREAM_STATUS;
var localVideo;

$(document).ready(function () {
    init_page();
});

function init_page() {
   
    try {
        Flashphoner.init({flashMediaProviderSwfLocation: base_url+'web/js/flashphoner/media-provider.swf'});
    } catch(e) {
        console.log("Your browser doesn't support Flash or WebRTC technology necessary for work of an example");
        return;
    }
    Flashphoner.getMediaDevices(null, true).then(function (list) {
        list.audio.forEach(function (device) {
            var audio = document.getElementById("audioInput");
            var i;
            var deviceInList = false;
            for (i = 0; i < audio.options.length; i++) {
                if (audio.options[i].value == device.id) {
                    deviceInList = true;
                    break;
                }
            }
            if (!deviceInList) {
                var option = document.createElement("option");
                option.text = device.label || device.id;
                option.value = device.id;
                audio.appendChild(option);
                option = null;
            }
        });
        list.video.forEach(function (device) {
            console.log(device);
            var video = document.getElementById("videoInput");
            var i;
            var deviceInList = false;
            for (i = 0; i < video.options.length; i++) {
                if (video.options[i].value == device.id) {
                    deviceInList = true;
                    break;
                }
            }
            if (!deviceInList) {
                var option = document.createElement("option");
                option.text = device.label || device.id;
                option.value = device.id;
                video.appendChild(option);
                option = null;
            }
        });
    }).catch(function (error) {
        console.log("Failed to get media devices");
    });
    //local displays
    localVideo = document.getElementById("localVideo");

    onStopped();
    return false;
    //set initial button callback
   
}

function onStarted(previewStream) {
    $("#publishBtn").text("Stop").off('click').click(function(){
        $(this).prop('disabled', true);
        previewStream.stop();
        previewStream = null;

    }).prop('disabled', false);
}

function onStopped() {
    $("#publishBtn").text("GO LIVE").off('click').click(function(){
        // Start and push stream to facebook using webcall server
       
        start();

        return false;

        //$("#audioInput").prop('disabled', true);
        //$("#videoInput").prop('disabled', true);
        //$("#videoSettings").prop('disabled', true);
    }).prop('disabled', false);
  
}

function start() {
    $("#loading_div_cont").fadeIn("slow");
    var url = 'wss://webc.domainname.com:8443';
    //check if we already have session
    if (Flashphoner.getSessions().length > 0) {
        var session = Flashphoner.getSessions()[0];
        if (session.getServerUrl() == url) {
            startStreaming(session);
            return;
        } else {
            //remove session DISCONNECTED and FAILED callbacks
            session.on(SESSION_STATUS.DISCONNECTED, function () {
            });
            session.on(SESSION_STATUS.FAILED, function () {
            });
            session.disconnect();
        }
    }
    else
    {
        //create session
        console.log("Create new session with url " + url);
        Flashphoner.createSession({urlServer: url}).on(SESSION_STATUS.ESTABLISHED, function(session){
        //session connected, start streaming
        startStreaming(session);
        }).on(SESSION_STATUS.DISCONNECTED, function(){
            setStatus(SESSION_STATUS.DISCONNECTED);
            onStopped();
        }).on(SESSION_STATUS.FAILED, function(){
            setStatus(SESSION_STATUS.FAILED);
            onStopped();
        });
    }
}

function startStreaming(session)
{
    videoSettings = videoSettings.split('x');

    console.log('selected video settings = '+videoSettings[0]+'X'+videoSettings[1]);
    //console.log('fb_stream_name = '+fb_stream_name);
    //console.log('fb_live_video_id = '+fb_live_video_id);
    videoSettings[0] = parseInt(videoSettings[0]);
    videoSettings[1] = parseInt(videoSettings[1]);

    var video_width = 1280;
    var video_height = 720;

    if (videoSettings[0] == 1280)
    {
        video_width = 1280;
        video_height = 720;
    }
    else
    if (videoSettings[0] == 720)
    {
        video_width = 720;
        video_height = 720;
    }
    else
    if (videoSettings[0] == 640)
    {
        video_width = 720;
        video_height = 480;
    }
    videoSettings = videoSettings[0]+"x"+videoSettings[1];

    var constraints = {
        audio: {
            deviceId: $('#audioInput').val(),
            bitrate: 1048576 // 128Kbps
        },
        video: {
            deviceId: $('#videoInput').val(),
            width: video_width,
            height: video_height,
            bitrate: (((8*1024)*1024)*2.0), // 2.0Mbps
            frameRate: 30      
        }
    };
    video_width = null;
    video_height = null;
    session.createStream({
        name: fb_stream_name,
        display: localVideo,
        cacheLocalResources: true,
        receiveVideo: false,
        receiveAudio: false,
        flashShowFullScreenButton: true,
        constraints: constraints,
        rtmpUrl: fb_rtmp_url
    }).on(STREAM_STATUS.PUBLISHING, function(publishStream){

        setStatus(STREAM_STATUS.PUBLISHING);
        onStarted(publishStream);
       
    }).on(STREAM_STATUS.UNPUBLISHED, function(){
        setStatus(STREAM_STATUS.UNPUBLISHED);
        //enable start button
        onStopped();
       
    }).on(STREAM_STATUS.FAILED, function(){
        setStatus(STREAM_STATUS.FAILED);
        //enable start button
        onStopped();
       
    }).publish();
    constraints = null;
   

   
    session = null;

}


//show connection or local stream status
function setStatus(status)
{
    console.log('Status change detected = '+status);

    // var statusField = $("#status");
    // statusField.text(status).removeClass();
    // if (status == "PUBLISHING") {
    //     statusField.attr("class","text-success");
    // } else if (status == "DISCONNECTED" || status == "UNPUBLISHED") {
    //     statusField.attr("class","text-muted");
    // } else if (status == "FAILED") {
    //     statusField.attr("class","text-danger");
    // }
}

Thanks,
Faraz
 

Max

Administrator
Staff member
You are using trial license on this server.
The trial license can stop working anytime when it has any issues with time sync checks.
It is not designed for production and continuous running.
Please use regular license to fix this issue.
 
Top