Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F462868
AphlictPeer.js
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
AphlictPeer.js
View Options
'use strict'
;
var
JX
=
require
(
'./javelin'
).
JX
;
var
http
=
require
(
'http'
);
var
https
=
require
(
'https'
);
JX
.
install
(
'AphlictPeer'
,
{
construct
:
function
()
{
},
properties
:
{
host
:
null
,
port
:
null
,
protocol
:
null
,
fingerprint
:
null
},
members
:
{
broadcastMessage
:
function
(
instance
,
message
)
{
var
data
;
try
{
data
=
JSON
.
stringify
(
message
);
}
catch
(
error
)
{
return
;
}
// TODO: Maybe use "agent" stuff to pool connections?
var
options
=
{
hostname
:
this
.
getHost
(),
port
:
this
.
getPort
(),
method
:
'POST'
,
path
:
'/?instance='
+
instance
,
headers
:
{
'Content-Type'
:
'application/json'
,
'Content-Length'
:
data
.
length
}
};
var
onresponse
=
JX
.
bind
(
this
,
this
.
_onresponse
);
var
request
;
if
(
this
.
getProtocol
()
==
'https'
)
{
request
=
https
.
request
(
options
,
onresponse
);
}
else
{
request
=
http
.
request
(
options
,
onresponse
);
}
request
.
write
(
data
);
request
.
end
();
},
_onresponse
:
function
(
response
)
{
var
peer
=
this
;
var
data
=
''
;
response
.
on
(
'data'
,
function
(
bytes
)
{
data
+=
bytes
;
});
response
.
on
(
'end'
,
function
()
{
var
message
;
try
{
message
=
JSON
.
parse
(
data
);
}
catch
(
error
)
{
return
;
}
// If we got a valid receipt, update the fingerprint for this server.
var
fingerprint
=
message
.
fingerprint
;
if
(
fingerprint
)
{
peer
.
setFingerprint
(
fingerprint
);
}
});
}
}
});
File Metadata
Details
Attached
Mime Type
application/javascript
Expires
Mon, May 5, 6:35 PM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
73398
Default Alt Text
AphlictPeer.js (1 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment