Skip to content

Commit

Permalink
#16 add controlPeerStruktur
Browse files Browse the repository at this point in the history
  • Loading branch information
TorbenHaug committed Dec 9, 2016
1 parent 94ffd42 commit 9532a19
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
12 changes: 12 additions & 0 deletions src/public/ControlPeer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html>
<head></head>


<body>
<div align='center' id='info'>
Placeholder ControlPeer!
</div>

<script src="js/ControlPeer_Bundle.js"></script>
</body>
</html>
21 changes: 13 additions & 8 deletions src/public/js/ControlPeerCommunicationHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* For further information:
*
* Sequence including this Entity:
* Sequence including this Entity:
* https://raw.githubusercontent.com/Transport-Protocol/MBC-Ping-Pong
* /master/docu/maindocumentation/architecture/prototypSequenceDiagram.png
*
Expand All @@ -15,6 +15,11 @@

var P2P = require('socket.io-p2p');
var io = require('socket.io-client');

//Interface
module.exports.init = init;
module.exports.sendPosition = sendPosition;

var opts = { autoUpgrade: false, peerOpts: {numClients: 10} };

// Predefined vars used in init
Expand All @@ -34,27 +39,27 @@ function init(){
function initCommunication(){
iosocket = io.connect();
p2psocket = new P2P(iosocket, opts, null);

iosocket.on('connect', function(){
console.log("Now Connected to the Server.");
isConnected = true;
});

p2psocket.on('ready', function(){});

p2psocket.on('upgradewebrtc', function(){
if(isPeer2Peer) return;

p2psocket.upgrade();
isPeer2Peer = true;
});
}

function sendPosition(posx, posy){
if(!isConnected || !isPeer2Peeer) return;

console.log("Sending new Position: ["+posx+","+posy+"]");

var position = {PlayerId: "someID", X: posx, Y: posy};
p2psocket.emit('changeposition', position);
}
}
1 change: 1 addition & 0 deletions src/public/js/ControlPeerMain.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var FingerPositionHandler = require('./FingerPositionHandler.js');
1 change: 1 addition & 0 deletions src/public/js/FingerPositionHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var ControlPeerCommunicationHandler = require('./ControlPeerCommunicationHandler.js');

0 comments on commit 9532a19

Please sign in to comment.