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
24a81b19
authored
2020-05-03 18:33:10 +0700
by
Jabis Sevón
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
relaypeers option
1 parent
fd27afd0
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
17 deletions
server.js
server.js
View file @
24a81b1
...
...
@@ -3,8 +3,7 @@
* Each Gun is scoped to its ws.path and intended for ephemeral usage
* MIT Licensed (C) QXIP 2020
*/
var
no
=
require
(
'gun/lib/nomem'
)();
// no-memory storage adapter for RAD
const
no
=
require
(
'gun/lib/nomem'
)();
// no-memory storage adapter for RAD
const
fs
=
require
(
"fs"
);
const
url
=
require
(
"url"
);
const
Gun
=
require
(
"gun"
);
// load defaults
...
...
@@ -16,8 +15,9 @@ const SEA = Gun.SEA;
const
http
=
require
(
"http"
);
const
https
=
require
(
"https"
);
const
WebSocket
=
require
(
"ws"
);
var
debug
=
process
.
env
.
DEBUG
||
true
;
var
config
=
{};
let
debug
=
process
.
env
.
DEBUG
||
true
;
let
relaypeers
=
process
.
env
.
RELAY
||
'https://mg.rig.airfaas.com/'
;
let
config
=
{};
if
(
debug
)
console
.
log
(
SEA
,
Gun
.
SEA
);
config
.
options
=
{
}
...
...
@@ -50,7 +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
(
debug
)
console
.
log
(
"roomname"
,
roomname
);
if
(
lru
.
has
(
pathname
))
{
// Existing Node
if
(
debug
)
console
.
log
(
"Recycle id"
,
pathname
);
...
...
@@ -70,12 +70,16 @@ server.on("upgrade", async function(request, socket, head) {
/*Gun.on('opt',function(ctx){
if(ctx.once) return;
ctx.on('in',function(msg){
console.log(msg);
if(debug)
console.log(msg);
this.to.next(msg);
})
})*/
let
qs
=
[
"sig="
+
encodeURIComponent
((
sig
?
sig
:
''
)),
"creator="
+
encodeURIComponent
((
creator
?
creator
:
''
))].
join
(
"&"
);
let
relaypath
=
pathname
+
'?'
+
qs
;
let
peers
=
relaypeers
.
split
(
','
).
map
(
function
(
p
){
return
p
+
relaypath
;
});
if
(
debug
)
console
.
log
(
"peers"
,
peers
);
const
g
=
gun
.
gun
=
Gun
({
peers
:
[]
,
// should we use self as peer?
peers
:
peers
,
// should we use self as peer?
localStorage
:
false
,
store
:
no
,
file
:
"tmp"
+
pathname
,
// make sure not to reuse same storage context
...
...
@@ -85,25 +89,30 @@ server.on("upgrade", async function(request, socket, head) {
});
gun
.
server
=
gun
.
gun
.
back
(
'opt.ws.web'
);
// this is the websocket server
lru
.
set
(
pathname
,
gun
);
let
obj
=
{
roomname
:
roomname
,
creator
:
creator
,
socket
:{}};
let
obj
=
{
roomname
:
roomname
,
creator
:
creator
};
if
(
debug
)
console
.
log
(
'object is'
,
obj
);
if
(
sig
)
{
let
user
=
g
.
user
();
user
.
create
(
roomname
,
sig
,
async
function
(
dack
){
console
.
log
(
"We've got user create ack"
,
dack
,
roomname
,
sig
);
user
.
create
(
roomname
,
sig
,
function
(
dack
){
if
(
debug
)
console
.
log
(
"We've got user create ack"
,
dack
,
roomname
,
sig
);
if
(
dack
.
err
){
console
.
log
(
"error in user.create"
,
dack
.
err
);
}
user
.
auth
(
roomname
,
sig
,
async
function
(
auth
){
console
.
log
(
"We've got user auth ack"
,
auth
);
user
.
auth
(
roomname
,
sig
,
function
(
auth
){
if
(
debug
)
console
.
log
(
"We've got user auth ack"
,
auth
);
if
(
auth
.
err
){
console
.
log
(
'error in auth'
,
auth
.
err
);
}
//console.log("auth",auth,roomname,sig);
Object
.
assign
(
obj
,{
pub
:
dack
.
pub
,
passwordProtected
:
true
passwordProtected
:
'true'
});
console
.
log
(
"putting object to user"
,
obj
,
user
);
if
(
debug
)
console
.
log
(
"putting"
,
roomname
,
"with object"
,
obj
,
`to user
${
dack
.
pub
}
`
);
user
.
get
(
roomname
).
put
(
obj
,
function
(
roomack
){
//TODO: @marknadal fix me
console
.
log
(
"roomnode?"
,
roomack
);
if
(
debug
)
console
.
log
(
"roomnode?"
,
roomack
);
var
roomnode
=
user
.
get
(
roomname
);
g
.
get
(
'rtcmeeting'
).
get
(
roomname
).
put
(
roomnode
,
function
(
puback
){
console
.
log
(
"put object"
,
puback
);
if
(
debug
)
console
.
log
(
"put object"
,
puback
);
});
});
});
...
...
@@ -111,7 +120,7 @@ server.on("upgrade", async function(request, socket, head) {
}
else
{
Object
.
assign
(
obj
,{
passwordProtected
:
false
});
g
.
get
(
"rtcmeeting"
).
get
(
roomname
).
put
(
obj
,
function
(
grack
){
console
.
log
(
"room created"
,
grack
);
if
(
debug
)
console
.
log
(
"room created"
,
grack
);
});
}
}
...
...
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