Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Jabis Sevón
/
gun-multiserver
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
a5927ea8
authored
2020-05-02 13:51:26 +0700
by
Jabis Sevón
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
merge marks multigun patch
1 parent
b2c715bd
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
27 deletions
README.md
mem.js
package.json
server.js
README.md
View file @
a5927ea


#
GunDB
MultiSocket
Single
`HTTP/S`
server providing
`WebSocket`
Path based routing to ephemeral
[
GunDB
](
https://gun.eco
)
instances in
mesh isolation.
#
### Gun
MultiSocket
Single
`HTTP/S`
server providing
multiple ephemeral
[
GunDB
](
https://gun.eco
)
`WebSocket`
instances with path based routing and
mesh isolation.
### Notes
*
uses its own
[
mem
](
https://github.com/meething/gundb-multisocket/blob/master/mem.js
)
storage adaptor to avoid any disk writes
...
...
mem.js
View file @
a5927ea
...
...
@@ -22,8 +22,8 @@
return
;
}
to
=
setTimeout
(
flush
,
opt
.
wait
||
1
);
//
var id = at['#']
//
ctx.on('in', {"@": id, ok:1})
//
var id = at['#']
//
ctx.on('in', {"@": id, ok:1})
});
ctx
.
on
(
'get'
,
function
(
at
){
//console.log("get at",at,disk);
...
...
package.json
View file @
a5927ea
...
...
@@ -9,7 +9,7 @@
},
"dependencies"
:
{
"express"
:
"^4.17.1"
,
"gun"
:
"^0.2020.4
01
"
,
"gun"
:
"^0.2020.4
30
"
,
"quick-lru"
:
"^5.1.0"
},
"engines"
:
{
...
...
server.js
View file @
a5927ea
...
...
@@ -4,11 +4,12 @@
* MIT Licensed (C) QXIP 2020
*/
var
no
=
require
(
'gun/lib/nomem'
)();
// no-memory storage adapter for RAD
const
fs
=
require
(
"fs"
);
const
url
=
require
(
"url"
);
const
Gun
=
require
(
"gun
/gun"
);
// do not load storage adaptors by default
require
(
"./gun-ws.js"
);
// required to allow external websockets into gun constructor
require
(
"./mem.js"
);
// disable to allow file writing for debug
const
Gun
=
require
(
"gun
"
);
// load defaults
//
require("./gun-ws.js"); // required to allow external websockets into gun constructor
//
require("./mem.js"); // disable to allow file writing for debug
require
(
"gun/sea"
);
require
(
"gun/lib/then"
);
const
SEA
=
Gun
.
SEA
;
...
...
@@ -17,10 +18,9 @@ const https = require("https");
const
WebSocket
=
require
(
"ws"
);
var
debug
=
process
.
env
.
DEBUG
||
false
;
var
config
=
{};
config
.
options
=
{
}
if
(
!
process
.
env
.
hasOwnProperty
(
'SSL'
)
||
process
.
env
.
SSL
==
false
)
{
var
server
=
http
.
createServer
();
server
.
listen
(
process
.
env
.
PORT
||
8767
);
...
...
@@ -50,6 +50,7 @@ server.on("upgrade", async function(request, socket, head) {
var
gun
=
{
gun
:
false
,
server
:
false
};
if
(
pathname
)
{
let
roomname
=
pathname
.
split
(
""
).
slice
(
1
).
join
(
""
);
console
.
log
(
"roomname"
,
roomname
);
if
(
lru
.
has
(
pathname
))
{
// Existing Node
if
(
debug
)
console
.
log
(
"Recycle id"
,
pathname
);
...
...
@@ -65,7 +66,7 @@ server.on("upgrade", async function(request, socket, head) {
if
(
debug
)
console
.
log
(
"stored sig "
,
sig
,
"to pathname"
,
pathname
);
}
//console.log("gunsea",Gun.SEA);
SEA
.
throw
=
1
;
//
SEA.throw = 1;
/*Gun.on('opt',function(ctx){
if(ctx.once) return;
ctx.on('in',function(msg){
...
...
@@ -82,34 +83,34 @@ server.on("upgrade", async function(request, socket, head) {
ws
:
{
noServer
:
true
,
path
:
pathname
,
web
:
gun
.
server
},
web
:
gun
.
server
});
gun
.
server
=
gun
.
gun
.
back
(
'opt.ws.web'
);
// this is the websocket server
lru
.
set
(
pathname
,
gun
);
let
obj
=
{
roomname
:
roomname
,
creator
:
creator
,
socket
:{}};
if
(
sig
)
{
let
user
=
g
.
user
();
user
.
create
(
roomname
,
sig
,
async
function
(
ack
){
console
.
log
(
"We've got create ack"
,
ack
);
if
(
ack
.
err
){
console
.
log
(
"error in user.create"
,
ack
.
err
);
}
let
auth
=
await
new
Promise
((
res
,
rej
)
=>
{
return
user
.
auth
(
roomname
,
sig
,
res
);
});
user
.
create
(
roomname
,
sig
,
async
function
(
dack
){
console
.
log
(
"We've got create ack"
,
dack
,
roomname
,
sig
);
if
(
dack
.
err
){
console
.
log
(
"error in user.create"
,
dack
.
err
);
}
user
.
auth
(
roomname
,
sig
,
function
(
auth
){
if
(
auth
.
err
){
console
.
log
(
'error in auth'
,
auth
.
err
);
}
console
.
log
(
"auth"
,
auth
);
console
.
log
(
"auth"
,
auth
,
roomname
,
sig
);
Object
.
assign
(
obj
,{
pub
:
ack
.
pub
,
pub
:
d
ack
.
pub
,
passwordProtected
:
true
})
let
roomnode
=
user
.
get
(
roomname
).
put
(
obj
);
let
putnode
=
g
.
get
(
'rtcmeeting'
).
get
(
roomname
).
put
(
roomnode
);
let
rack
=
await
putnode
.
then
();
console
.
log
(
"room created"
,
rack
);
let
putnode
=
g
.
get
(
'rtcmeeting'
).
get
(
roomname
);
let
rack
=
putnode
.
put
(
roomnode
);
console
.
log
(
"room created"
);
rack
.
once
(
Gun
.
log
);
});
});
}
else
{
;(
async
()
=>
{
Object
.
assign
(
obj
,{
passwordProtected
:
false
});
let
roomnode
=
g
.
get
(
"rtcmeeting"
).
get
(
roomname
).
put
(
obj
);
let
rack
=
await
roomnode
.
then
();
let
roomnode
=
g
.
get
(
"rtcmeeting"
).
get
(
roomname
).
put
(
obj
,
function
(
rack
){
console
.
log
(
"room created"
,
rack
);
})
()
})
;
}
}
}
...
...
@@ -120,6 +121,7 @@ server.on("upgrade", async function(request, socket, head) {
gun
.
server
.
emit
(
"connection"
,
ws
,
request
);
});
}
else
{
if
(
debug
)
console
.
log
(
"destroying socket"
,
pathname
);
socket
.
destroy
();
}
});
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment