mirror of
https://github.com/amark/gun.git
synced 2025-06-06 22:26:48 +00:00
Isolate websocket logic
WebSocket logic has it's own folder now, `wsp`.
This commit is contained in:
parent
adbea08120
commit
e36e78f532
@ -3,7 +3,7 @@
|
|||||||
var Gun = require('../gun');
|
var Gun = require('../gun');
|
||||||
console.log("TODO: MARK! UPDATE S3 DRIVER BEFORE PUBLISHING!")
|
console.log("TODO: MARK! UPDATE S3 DRIVER BEFORE PUBLISHING!")
|
||||||
//require('./s3');
|
//require('./s3');
|
||||||
require('./wsp');
|
require('./wsp/server');
|
||||||
require('./file');
|
require('./file');
|
||||||
module.exports = Gun;
|
module.exports = Gun;
|
||||||
}());
|
}());
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var Gun = require('../gun');
|
var Gun = require('../../gun');
|
||||||
var WS = require('ws');
|
var WS = require('ws');
|
||||||
|
|
||||||
var Tab = {};
|
var Tab = {};
|
@ -1,14 +1,14 @@
|
|||||||
/* eslint-disable*/
|
/* eslint-disable*/
|
||||||
var Gun = require('../gun')
|
var Gun = require('../../gun')
|
||||||
, formidable = require('formidable')
|
, formidable = require('formidable')
|
||||||
, http = require('./http')
|
, http = require('../http')
|
||||||
, url = require('url')
|
, url = require('url')
|
||||||
, wsp = {}
|
, wsp = {}
|
||||||
, WS = require('ws')
|
, WS = require('ws')
|
||||||
, ws = WS.Server;
|
, ws = WS.Server;
|
||||||
|
|
||||||
// Handles server to server sync.
|
// Handles server to server sync.
|
||||||
require('./wsp-client.js');
|
require('./client.js');
|
||||||
|
|
||||||
Gun.on('opt', function(at){
|
Gun.on('opt', function(at){
|
||||||
var gun = at.gun, opt = at.opt;
|
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(!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'){
|
if(msg.url.pathname.replace(gun.wsp.regex,'').slice(0,3).toLowerCase() === '.js'){
|
||||||
res.writeHead(200, {'Content-Type': 'text/javascript'});
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ Gun.on('opt', function(at){
|
|||||||
|
|
||||||
return http(req, res, function(req, res){
|
return http(req, res, function(req, res){
|
||||||
if(!req){ return next() }
|
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'])){
|
if(req.headers && (stream = req.headers['gun-sid'])){
|
||||||
stream = (gun.wsp.peers = gun.wsp.peers || {})[stream] = gun.wsp.peers[stream] || {sid: stream};
|
stream = (gun.wsp.peers = gun.wsp.peers || {})[stream] = gun.wsp.peers[stream] || {sid: stream};
|
||||||
stream.drain = stream.drain || function(res){
|
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.
|
// TODO: MARK! You should move the networking events to here, not in WSS only.
|
||||||
});
|
});
|
||||||
tran.json = 'application/json';
|
tran.json = 'application/json';
|
@ -1,4 +1,4 @@
|
|||||||
var Gun = require('../gun')
|
var Gun = require('../../gun')
|
||||||
, url = require('url');
|
, url = require('url');
|
||||||
module.exports = function(wss, server, opt){
|
module.exports = function(wss, server, opt){
|
||||||
wss.on('connection', function(ws){
|
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'];
|
(reply.headers = reply.headers || {})['ws-rid'] = msg.headers['ws-rid'];
|
||||||
}
|
}
|
||||||
try{ws.send(Gun.text.ify(reply));
|
try{ws.send(Gun.text.ify(reply));
|
||||||
}catch(e){} // juuuust in case.
|
}catch(e){} // juuuust in case.
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
ws.off = function(m){
|
ws.off = function(m){
|
Loading…
x
Reference in New Issue
Block a user