Isolate websocket logic

WebSocket logic has it's own folder now, `wsp`.
This commit is contained in:
Jesse Gibson 2016-11-10 10:09:18 -07:00
parent adbea08120
commit e36e78f532
4 changed files with 10 additions and 10 deletions

View File

@ -3,7 +3,7 @@
var Gun = require('../gun');
console.log("TODO: MARK! UPDATE S3 DRIVER BEFORE PUBLISHING!")
//require('./s3');
require('./wsp');
require('./wsp/server');
require('./file');
module.exports = Gun;
}());

View File

@ -8,7 +8,7 @@
*/
'use strict';
var Gun = require('../gun');
var Gun = require('../../gun');
var WS = require('ws');
var Tab = {};

View File

@ -1,14 +1,14 @@
/* eslint-disable*/
var Gun = require('../gun')
var Gun = require('../../gun')
, formidable = require('formidable')
, http = require('./http')
, http = require('../http')
, url = require('url')
, wsp = {}
, WS = require('ws')
, ws = WS.Server;
// Handles server to server sync.
require('./wsp-client.js');
require('./client.js');
Gun.on('opt', function(at){
var gun = at.gun, opt = at.opt;
@ -67,7 +67,7 @@ Gun.on('opt', function(at){
if(!gun.wsp.regex.test(msg.url.pathname)){ return next(), false } // TODO: BUG! If the option isn't a regex then this will fail!
if(msg.url.pathname.replace(gun.wsp.regex,'').slice(0,3).toLowerCase() === '.js'){
res.writeHead(200, {'Content-Type': 'text/javascript'});
res.end(gun.wsp.js = gun.wsp.js || require('fs').readFileSync(__dirname + '/../gun.js')); // gun server is caching the gun library for the client
res.end(gun.wsp.js = gun.wsp.js || require('fs').readFileSync(__dirname + '/../../gun.js')); // gun server is caching the gun library for the client
return true;
}
@ -78,7 +78,7 @@ Gun.on('opt', function(at){
return http(req, res, function(req, res){
if(!req){ return next() }
var stream, cb = res = require('./jsonp')(req, res);
var stream, cb = res = require('../jsonp')(req, res);
if(req.headers && (stream = req.headers['gun-sid'])){
stream = (gun.wsp.peers = gun.wsp.peers || {})[stream] = gun.wsp.peers[stream] || {sid: stream};
stream.drain = stream.drain || function(res){
@ -172,7 +172,7 @@ Gun.on('opt', function(at){
}});
})});
}
gun.wsp.on('network', function(req){
gun.wsp.on('network', function(rq){
// TODO: MARK! You should move the networking events to here, not in WSS only.
});
tran.json = 'application/json';

View File

@ -1,4 +1,4 @@
var Gun = require('../gun')
var Gun = require('../../gun')
, url = require('url');
module.exports = function(wss, server, opt){
wss.on('connection', function(ws){
@ -27,7 +27,7 @@ module.exports = function(wss, server, opt){
(reply.headers = reply.headers || {})['ws-rid'] = msg.headers['ws-rid'];
}
try{ws.send(Gun.text.ify(reply));
}catch(e){} // juuuust in case.
}catch(e){} // juuuust in case.
});
});
ws.off = function(m){