FabianGort / PeerSquared

PeerSquared - online teaching
MIT License
7 stars 10 forks source link

How to launch PeerSquared locally in development #1

Open BartlomiejSkwira opened 10 years ago

BartlomiejSkwira commented 10 years ago

Hi I'm trying to launch Peer Squared locally, readme doesn't give much info on this. Here is what I did:

  1. Started a faye/websocket server in parallel (in another rails project, it's running on )
  2. Cloned Peer Squared and launched index.html in browser with path:
file:///Users/../workspace/PeerSquared/index.html#student_user@example.com_mychan
  1. Launching index caused a JS error: 'Uncaught ReferenceError: mozRTCSessionDescription is not defined' in file 'peersquared.min.js' in line:

A Fix: replace mozRTCSessionDescription with RTCSessionDescription

  1. Next issue: I've added line `PR2.init(credentials)' in index.html file error: 'Uncaught ReferenceError: PR2 is not defined '

Fix: add <script src="script/PR2.js"></script> at top on index.html

  1. Next issue: a) Uncaught TypeError: Object #<Object> has no method 'init' b) XMLHttpRequest cannot load file:///Users/bs/workspace/ruby/PeerSquared/auth.php?your_name=student. Cross origin requests are only supported for HTTP

Here is my index.html file:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
 <title>PeerSquared</title>
 <link rel="stylesheet" href="css/canvas.css" />
</head>
<body>

<script src="script/PR2.js"></script>
<script>
var user = location.hash.slice(1).split('_');
console.log(user);
var credentials = {level : user[0], name : user[0], channel :user[1]};

PR2.init(credentials);

window.onbeforeunload = function() {
  if(PR2.peer.isConnected()) {
    PR2.peer.sendData(JSON.stringify({type : 'close-connection'}));
  }
}

</script>
<script src="http://js.pusher.com/2.0/pusher.min.js" type="text/javascript"></script>
<script src="script/Pusher_Socket.js"></script> 
<script src="script/peersquared.min.js"></script>

</body>
</html>

Any help would be great.

FabianGort commented 10 years ago

Hello,

I haven't been working on this version of PeerSquared for some times, but I notice you use local paths 'file///' and then you get errors with cross-origin requests. So I would start with launching it from a http url (localhost e.g.).

I don't think that adding PR2.js to the top is a good thing to do.
Also, for development I really don't recommend the minified version, since it is hard to debug. So I would change the

line

with

And when you have it working the way you want minify it again.

Regards,

Fabian

BartlomiejSkwira schreef op 20-3-2014 10:46:

Hi I'm trying to launch Peer Squared locally, readme doesn't give much info on this. Here is what I did:

  1. Started a faye/websocket server in parallel (in another rails project, it's running on )
  2. Cloned Peer Squared and launched index.html in browser with path:
file:///Users/../workspace/PeerSquared/index.html#student_user@example.com_mychan
  1. Launching index caused a JS error: 'Uncaught ReferenceError: mozRTCSessionDescription is not defined' in file 'peersquared.min.js' in line:

A Fix: replace |mozRTCSessionDescription| with |RTCSessionDescription|

  1. Next issue: I've added line `PR2.init(credentials)' in index.html file error: 'Uncaught ReferenceError: PR2 is not defined '

Fix: add || at top on index.html

  1. Next issue: a) |Uncaught TypeError: Object # has no method 'init'| b) |XMLHttpRequest cannot load file:///Users/bs/workspace/ruby/PeerSquared/auth.php?your_name=student. Cross origin requests are only supported for HTTP|

    Here is my index.html file:

    |<!DOCTYPE html>

    PeerSquared

    |

    Any help would be great.

    — Reply to this email directly or view it on GitHub https://github.com/FabianGort/PeerSquared/issues/1.

    BartlomiejSkwira commented 10 years ago

    Yes, I was static loading the file in a browser, when served from a server, removed PR.init() it started to work (with the demo app package). Also I am not using the minified version anymore.

    [edit]: nevermind, its a client

    FabianGort commented 10 years ago

    Yes, you need to implement the onusersconnect/onmessage handlers and the open/send/close methods into a websocket connection object, and that is about it. So connect two users to a channel,check if the channel contains two users and if so fire 'onusersconnect'. Then you make sure that the send method sends data to the websocket channel and that the onmessage handler receives that data on the other client.

    BartlomiejSkwira schreef op 20-3-2014 14:33:

    Yes, I was static loading the file in a browser, when served from a server, removed PR.init() it started to work (with the demo app package). Also we are not using the minified version anymore. One more question, I want to create a server in socket.io which will handle communication, should I basically handle all the stuff that is in https://github.com/FabianGort/PeerSquared/blob/master/script/Pusher_Socket.js

    — Reply to this email directly or view it on GitHub https://github.com/FabianGort/PeerSquared/issues/1#issuecomment-38166614.

    BartlomiejSkwira commented 10 years ago

    Ok so I wrote a client and server in newest socket.io but I'm experiencing this bug: https://github.com/LearnBoost/socket.io-client/issues/641#issuecomment-38181408

    Could you share your server implementation (used here https://fabfactory.cloud.tilaa.com:8000/)? I would then use the 2011 socket.io version as it works with Peer Squared.

    BartlomiejSkwira commented 10 years ago

    @FabianGort if you don't want to share that's fine. Maybe you could take a look at my issue? I'm really in a blind spot here and am considering moving to faye from socket.io

    FabianGort commented 10 years ago

    It's ok for you to have it, I was just a bit occupied. I put the javascript file as a rar file in the attachment, to prevent virus scanner troubles.

    As you can see I use https, so you will need to get your certificates if you want to use this script.

    BartlomiejSkwira schreef op 24-3-2014 9:54:

    @FabianGort https://github.com/FabianGort if you don't want to share that's fine. Maybe you could take a look at my issue? I'm really in a blind spot here and am considering moving to faye from socket.io

    — Reply to this email directly or view it on GitHub https://github.com/FabianGort/PeerSquared/issues/1#issuecomment-38422305.

    BartlomiejSkwira commented 10 years ago

    And where is the rar file?

    FabianGort commented 10 years ago

    Maybe it's filtered by github. If you give me your mail address I can try to send it there

    BartlomiejSkwira schreef op 25-3-2014 11:59:

    And where is the rar file?

    — Reply to this email directly or view it on GitHub https://github.com/FabianGort/PeerSquared/issues/1#issuecomment-38551511.

    BartlomiejSkwira commented 10 years ago

    I'm not a fan of pasting emails publicly, how about putting the code here https://gist.github.com/

    FabianGort commented 10 years ago

    How about getting a disposable address or alias for such matters?

    BartlomiejSkwira schreef op 25-3-2014 16:49:

    I'm not a fan of pasting emails publicly, how about putting the code here https://gist.github.com/

    — Reply to this email directly or view it on GitHub https://github.com/FabianGort/PeerSquared/issues/1#issuecomment-38581256.

    FabianGort commented 10 years ago

    Here is just the plain text, should work too

    var https = require('https'), socket_io = require('socket.io'), fs = require('fs');

    var options = { ca: fs.readFileSync('../../etc/ssl/certificates/fabfactory.ca-bundle'), key: fs.readFileSync('../../etc/ssl/certificates/server.key'), cert: fs.readFileSync('../../etc/ssl/certificates/fabfactory_cloud_tilaa_com.crt') };

    var app = https.createServer(options, handler); var io = socket_io.listen(app);

    app.listen(8000);

    io.configure(function () { io.set("origins","fabfactory.cloud.tilaa.com:|localhost:|developer.cdn.mozilla.net:|www.fabfactory.eu:|fabfactory.eu:|developer.mozilla.org:|www.peersquared.info:|peersquared.info:|localhost:*"); });

    function handler (req, res) { fs.readFile(__dirname + '/index.html', function (err, data) {

             if (err) {
                 res.writeHead(500);
                 return res.end('Error loading index.html');
             }
             res.writeHead(200);
             res.end(data);
         });

    }

    io.sockets.on('connection', function (socket) { socket.on('join room', function(data){ // check for SHA-1 string if(data.room.match(/^[A-Za-z0-9]{40}$/) == null) { socket.emit('user error', {error: 'invalid room', message: 'The server will disconnect now'}); socket.disconnect(); } else if(io.sockets.clients(data.room).length > 2){ socket.emit('user error', {error: 'too many users', message: 'The server will disconnect now'}); socket.disconnect(); } else { socket.room = data.room; socket.join(socket.room); socket.emit('user joined', {user_count: io.sockets.clients(socket.room).length, user: 'current'}); socket.broadcast.to(socket.room).emit('user joined', {user_count: io.sockets.clients(socket.room).length, user: 'other'}); } }).on('disconnect', function(data){ socket.broadcast.to(socket.room).emit('user left', {data: 'left'}); }).on('webrtc', function(data) { // if(socket.room == data.room) { socket.broadcast.to(socket.room).emit('webrtc', data); // } }); });

    BartlomiejSkwira schreef op 25-3-2014 16:49:

    I'm not a fan of pasting emails publicly, how about putting the code here https://gist.github.com/

    — Reply to this email directly or view it on GitHub https://github.com/FabianGort/PeerSquared/issues/1#issuecomment-38581256.

    BartlomiejSkwira commented 10 years ago

    An alias or temp mail would work, but I see you pasted it. Thank you very much

    FabianGort commented 10 years ago

    Ok, good luck. If you don't have ssl, just switch the https to http module and remove the certificates from the options

    BartlomiejSkwira schreef op 26-3-2014 12:27:

    An alias or temp mail would work, but I see you pasted it. Thank you very much

    — Reply to this email directly or view it on GitHub https://github.com/FabianGort/PeerSquared/issues/1#issuecomment-38672877.

    BartlomiejSkwira commented 10 years ago

    SSL will depend on the client and if he wants it, in development we won't use it