Uncaught TypeError: Can not read property 'send' of undefined fancywebsocket.js:

0

I need help in the implementation of the socket, since I do not know why I get this error Uncaught TypeError: Cannot read property 'send' of undefined fancywebsocket.js: then the file class.PHPWebSocket.php , the servidor.php , its jQuery and fancywebsocket.js (which is where I get the error)

I will attach only the file in which the error is launched:

var Server;

$(document).ready(function() 
{
    Server = new FancyWebSocket('ws://192.168.1.13:8000');
    Server.bind('open', function()
    {
        console.log('opening');
    });
    Server.bind('close', function( data ) 
    {
        console.log('closing');
    });
    Server.bind('message', function( payload ) 
    {
        //alert('entro al message');
    });
    Server.connect();
});

function send( text ) 
{   // exactamente aqui abajo es donde me salta el error y me dice que no esta definida
    Server.send( 'message', text );//<-------------------
}///////////////////////////////////////////////////

function FancyWebSocket(url)
{
    var callbacks = {};
    var ws_url = url;
    var conn;

    this.bind = function(event_name, callback)
    {
        callbacks[event_name] = callbacks[event_name] || [];
        callbacks[event_name].push(callback);
        return this;
    };

    this.send = function(event_name, event_data)
    {
        this.conn.send( event_data );
        return this;
    };

    this.connect = function() 
    {
        if ( typeof(MozWebSocket) == 'function' )
        this.conn = new MozWebSocket(url);
        else
        this.conn = new WebSocket(url);

        this.conn.onmessage = function(evt)
        {
            dispatch('message', evt.data);
        };

        this.conn.onclose = function(){dispatch('close',null)}
        this.conn.onopen = function(){dispatch('open',null)}
    };

    this.disconnect = function()
    {
        this.conn.close();
    };

    var dispatch = function(event_name, message)
    {
        if(message == null || message == "")//aqui es donde se realiza toda la accion
            {
            }
            else
            {
                var JSONdata    = JSON.parse(message); //parseo la informacion
                var nombre = JSONdata[0].nombre;
                var nit = JSONdata[0].nit;
                var funcionario = JSONdata[0].funcionario;
                var nro_radicado = JSONdata[0].nro_radicado;
                var nrosolicitud = JSONdata[0].nrosolicitud;
                var consulta = JSONdata[0].consulta;
                var hora = JSONdata[0].hora;
// saber cual de los dos hay que mostrart
                var numeros;
                 if (nro_radicado != null) numeros=nro_radicado;
                 else if (nrosolicitud != null) numeros=nrosolicitud;
                 else numeros = 'POR DEFINIR';

//saber el tipo de boton que tiene
                var contenidoDiv  = $("#"+funcionario).html();
                var mensajehtml   = '<td width="35%">'+nombre+'</td>';
                    mensajehtml  += '<td width="25%">'+consulta+'</td>';
                    mensajehtml  += '<td width="15%">'+numeros+'</td>';
                    mensajehtml  += '<td width="10%">'+hora+'</td>';
                    mensajehtml  += '<td width="15%"><button type="submit" class="btn btn-danger btn-sm">EN ESPERA</button></td>';
                alert(funcionario);
                $("#"+funcionario).html(contenidoDiv+mensajehtml);
            }
    }
};

I appreciate your attention and the answers you can give me ... ReNiceCode ...

    
asked by srJJ 31.07.2018 в 02:02
source

0 answers