FabianGort/PeerSquared

How to launch PeerSquared locally in development

Opened this issue · 14 comments

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.

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

<script src="script/peersquared.min.js"></script>

with

<script src="script/PR2.js"></script> <script src="script/PR2_modules/utils.js"></script> <script src="script/PR2_modules/cambox.js"></script> <script src="script/PR2_modules/chatbox.js"></script> <script src="script/PR2_modules/download.js"></script> <script src="script/PR2_modules/fullscreen.js"></script> <script src="script/PR2_modules/modals.js"></script> <script src="script/PR2_modules/peer.js"></script> <script src="script/PR2_modules/shapes.js"></script> <script src="script/PR2_modules/shortcuts.js"></script> <script src="script/PR2_modules/toolbar.js"></script> <script src="script/PR2_modules/upload.js"></script> <script src="script/PR2_modules/user.js"></script> <script src="script/PR2_modules/whiteboard.js"></script> <script src="script/setup.js"></script>

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 |<script src="script/PR2.js"></script>| 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:

    |

    <title>PeerSquared</title> <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> |

    Any help would be great.


    Reply to this email directly or view it on GitHub
    #1.

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

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
#1 (comment).

Ok so I wrote a client and server in newest socket.io but I'm experiencing this bug: socketio/socket.io-client#641 (comment)

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.

@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

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
#1 (comment).

And where is the rar file?

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
#1 (comment).

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

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
#1 (comment).

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
#1 (comment).

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

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
#1 (comment).

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