{"id":2415,"date":"2015-09-19T12:02:59","date_gmt":"2015-09-19T17:02:59","guid":{"rendered":"http:\/\/www.jhclaura.com\/?p=2415"},"modified":"2015-09-19T16:28:22","modified_gmt":"2015-09-19T21:28:22","slug":"mask-v2-0-local-closed-network","status":"publish","type":"post","link":"http:\/\/www.jhclaura.com\/mask-v2-0-local-closed-network\/","title":{"rendered":"MASK v2.0 – Local server(*2) network!"},"content":{"rendered":"
<\/a><\/p>\n Quick notes on how I made\u00a0local Peer.js server, and also closed network!<\/p>\n When making my thesis, I used cloud hosted PeerServer with API key, so the project was constrained by\u00a0internet access. In order to make the project more robust and stable, I decided to create PeerServer on my own laptop,\u00a0and let devices (mobile phones) access the\u00a0laptop (server) through Wi-Fi.<\/p>\n Here are the quick notes on how I did those\u00a0(OMG such a googling \/ debugging hell!):<\/p>\n <\/p>\n Create PeerServer accompanying\u00a0another\u00a0WebSocket system<\/span><\/strong><\/p>\n Peer.js documented well about how to create your own PeerServer, even with examples\u00a0of combining with existing express app<\/a>, which is perfect for me. But because I have my own Node server as well, I struggled for a while to realize that, I should create two servers for each websocket with different ports!!! Finding\u00a0this out through non-stop console.log and try & error!<\/p>\n Server codes<\/em><\/span><\/p>\n <\/p>\n Client side\u00a0sudocode<\/em><\/span><\/p>\n <\/p>\n MacbookPro as server, accessing by devices through Wi-Fi with router<\/strong><\/span><\/p>\n Quick notes on how I made\u00a0local Peer.js server, and also closed network! When making my thesis, I used cloud hosted PeerServer with API key, so the project was constrained by\u00a0internet… Read The Rest →<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[127,268],"tags":[281,285,282,283,284],"_links":{"self":[{"href":"http:\/\/www.jhclaura.com\/wp-json\/wp\/v2\/posts\/2415"}],"collection":[{"href":"http:\/\/www.jhclaura.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.jhclaura.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.jhclaura.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.jhclaura.com\/wp-json\/wp\/v2\/comments?post=2415"}],"version-history":[{"count":10,"href":"http:\/\/www.jhclaura.com\/wp-json\/wp\/v2\/posts\/2415\/revisions"}],"predecessor-version":[{"id":2456,"href":"http:\/\/www.jhclaura.com\/wp-json\/wp\/v2\/posts\/2415\/revisions\/2456"}],"wp:attachment":[{"href":"http:\/\/www.jhclaura.com\/wp-json\/wp\/v2\/media?parent=2415"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.jhclaura.com\/wp-json\/wp\/v2\/categories?post=2415"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.jhclaura.com\/wp-json\/wp\/v2\/tags?post=2415"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}var express = require('express');\r\nvar app = express();\r\nvar http = require('http');\r\nvar server = http.createServer(app);\r\nvar port = process.env.PORT || 7000;\r\n\r\n\/\/ peer_server\r\nvar ExpressPeerServer = require('peer').ExpressPeerServer;\r\nvar peerExpress = require('express');\r\nvar peerApp = peerExpress();\r\nvar peerServer = require('http').createServer(peerApp);\r\nvar options = { debug: true }\r\nvar peerPort = 9000;\r\n\r\napp.get('*', function(req, res){\r\n res.sendFile(__dirname + req.url);\r\n});\r\npeerApp.use('\/pp', ExpressPeerServer(peerServer, options));\r\n\r\nserver.listen(port);\r\npeerServer.listen(peerPort);<\/pre>\n
var peerConnect = function() {\t\t\t\r\n\t\/* WebRTC - Peer.js *\/\r\n\tpeer = new Peer( ID(), { secure: false, host: 'YOUR_IP', port: 5000, path:'\/pp', debug:true} );\r\n\r\n\t\/\/ Get an ID from the PeerJS server\t\t\r\n\tpeer.on('open', function(id) {\r\n\t\tconsole.log('My peer ID is: ' + id);\r\n\t\tpeer_id = id;\r\n\r\n\t\t\/\/ Now we can connect to my socket server\t\t\t\t\t\t\r\n\t\tconnectSocket();\r\n\t});\r\n\r\n\tpeer.on('call', function(incoming_call) {\r\n\t\tconsole.log("Got a call!");\r\n\t\tincoming_call.answer(my_stream); \/\/ Answer the call with an A\/V stream.\r\n\t\t\/\/ do what you want~~~\r\n\t});\r\n};<\/pre>\n
\n
\n