(function() {
    var app  = {
        peers: []
    };

    app.events = {
        newPeer: function newPeer() {
            $('#id').text(app.peer.id);
        },
        checkRTC: function checkRTC(cb) {
            navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;

            if (!navigator.getUserMedia) {
                return cb({ err: 'Unssuported RTC' }, false);
            }

            navigator.getUserMedia({ audio: true, video: true }, cb, function(err) {
                console.err('An error occured: ', err);
            });
        },
        onReceiveStream: function onReceiveStream(stream, element_id) {
            var video = $('#' + element_id + ' video')[0];
            video.src = window.URL.createObjectURL(stream);
            window.peer_stream = stream;
        },
        peerConnect: function peerConnect(con) {
            app.peer.peer_id = con.peer;
            app.peer.con     = con;
            // con.on('data', handleMessage);

            $('.pattern_peer_id_connected').addClass('hidden').val(peer_id);
            $('#text_connected_peer').removeClass('hidden');
            $('#connected_peer').text(con.metadata.username);
        },
        onReceiveCall: function onReceiveCall(call) {
            call.answer(window.localStream);
            call.on('stream', function(stream){
              window.peer_stream = stream;
              app.events.onReceiveStream(stream, 'pattern-camera');
            });
        },
        peerCall: function peerCall(call) {
            return app.events.onReceiveCall(call);
        }
    };

    app.events.user = {
        login: function login() {
            var data = {
                username: $('#username').val(),
                peer_id: $('#peer_id').val()
            };

            if (data.peer_id) {
                app.peers.push(data);
                con = app.peer.connect(data.peer_id, { metadata: data });
                con.on('data', app.events.user.handleMessage);
            }

            $('.main').removeClass('hidden');
            $('.login-container').addClass('hidden');
        },
        call: function call() {
            console.log('calling: ', app.peer.peer_id);

            var call = app.peer.call(app.peer.peer_id, window.localStream);

            call.on('stream', function(stream) {
              window.peer_stream = stream;
              app.events.onReceiveStream(stream, 'pattern-camera');
            });
        },
        handleMessage: function handleMessage(data) {
            return $('#editor').val(data.editor);
        },
        editing: function editing() {
            var editor = $('#editor').val();
            var data = {
                editor: editor
            };

            app.peer.con.send(data);
            app.events.user.handleMessage(data);
            $('#message').val('');
        }
    }

    app.init = function init() {
        app.peer = new Peer({
            host: 'sonrtc-leonanllp.rhcloud.com',
            port: 8000,
            path: '/peerjs',
            debug: 3
        });

        app.peer.on('open', app.events.newPeer);
        app.peer.on('connection', app.events.peerConnect);
        app.peer.on('call', app.events.peerCall);

        app.events.checkRTC(function(stream) {
            window.localStream = stream;
            app.events.onReceiveStream(stream, 'my-camera');
        });

        $('#login').on('click', app.events.user.login);
        $('#call').on('click', app.events.user.call);
        $('#editor').on('input propertychange paste', app.events.user.editing);
    };

    app.init();
})();

@@ -2988,24 +2988,108 @@
 er(%7B%0A       
+     key: 'xmj30v615pfd2t9'%0A        %7D);%0A%0A        // app.peer = new Peer(%7B%0A        //
      host: '
@@ -3122,24 +3122,27 @@
 om',%0A       
+ //
      port: 8
@@ -3149,24 +3149,27 @@
 000,%0A       
+ //
      path: '
@@ -3181,24 +3181,27 @@
 js',%0A       
+ //
      debug: 
@@ -3201,32 +3201,35 @@
 debug: 3%0A       
+ //
  %7D);%0A%0A        ap

change server