lib/client/source/connectaPeer.js
function ondatachannel(e)
    {
        if(e)
        {
            scope._data = e.channel;
        }
        else
        {
            scope._data = scope._conn.createDataChannel("data");
        }

        scope._data.onopen = function()
        {
            if(scope._data)
            {
                if(scope._data.readyState == "open")
                {
                    if(scope.onChannelState)
                    {
                        scope.onChannelState(scope,'open');
                    }
                }
            }
        };
        scope._data.onmessage = function(e)
        {
            if(e.data instanceof ArrayBuffer)
            {
                if(scope.onBytesMessage)
                {
                    scope.onBytesMessage(scope,e.data);
                }
            }
            else
            {
                if(scope.onMessage)
                {
                    var char = Number(e.data[0]);

                    if(char == MessageType.MESSAGE)
                    {
                        scope.onMessage(scope,JSON.parse(e.data.substring(1,e.data.length)));
                    }
                    else
                    {
                        scope.onMessage(scope,e.data);
                    }
                }
            }
        }
        
        scope._data.onclose = function(e)
        {
            if(scope.onChannelState)
            {
                scope.onChannelState(scope,'closed');
            }
        }
        scope._data.onerror = function(e)
        {
            if(scope.onError)
            {
                scope.onError(e);
            }
        }
    }
function ondatachannel(e)
    {
        if(e)
        {
            scope._data = e.channel;
        }
        else
        {
            scope._data = scope._conn.createDataChannel("data");
        }

        scope._data.onopen = function()
        {
            if(scope._data)
            {
                if(scope._data.readyState == "open")
                {
                    if(scope.onChannelState)
                    {
                        scope.onChannelState(scope,'open');
                    }
                }
            }
        };
        scope._data.onmessage = function(e)
        {
            if(e.data instanceof ArrayBuffer)
            {
                if(scope.onBytesMessage)
                {
                    scope.onBytesMessage(scope,e.data);
                }
            }
            else
            {
                if(scope.onMessage)
                {
                    var char = Number(e.data[0]);

                    if(char == MessageType.MESSAGE)
                    {
                        scope.onMessage(scope,JSON.parse(e.data.substring(1,e.data.length)));
                    }
                    else
                    {
                        scope.onMessage(scope,e.data);
                    }
                }
            }
        }
        
        scope._data.onclose = function(e)
        {
            if(scope.onChannelState)
            {
                scope.onChannelState(scope,'closed');
            }
        }
        scope._data.onerror = function(e)
        {
            if(scope.onError)
            {
                scope.onError(e);
            }
        }
    }
function ondatachannel ( e ) { if ( e ) { scope . _data = e . channel ; } else { scope . _data = scope . _conn . createDataChannel ( "data" ) ; } scope . _data . onopen = function ( ) { if ( scope . _data ) { if ( scope . _data . readyState == "open" ) { if ( scope . onChannelState ) { scope . onChannelState ( scope , 'open' ) ; } } } } ; scope . _data . onmessage = function ( e ) { if ( e . data instanceof ArrayBuffer ) { if ( scope . onBytesMessage ) { scope . onBytesMessage ( scope , e . data ) ; } } else { if ( scope . onMessage ) { var char = Number ( e . data [ 0 ] ) ; if ( char == MessageType . MESSAGE ) { scope . onMessage ( scope , JSON . parse ( e . data . substring ( 1 , e . data . length ) ) ) ; } else { scope . onMessage ( scope , e . data ) ; } } } } scope . _data . onclose = function ( e ) { if ( scope . onChannelState ) { scope . onChannelState ( scope , 'closed' ) ; } } scope . _data . onerror = function ( e ) { if ( scope . onError ) { scope . onError ( e ) ; } } }
called when datachannel event is invoked, also called manually from offer to create new datachannel
called when datachannel event is invoked also called manually from offer to create new datachannel