Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F22425726
notifications.mjs
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
906 B
Referenced Files
None
Subscribers
None
notifications.mjs
View Options
import
{
WebSocket
}
from
"ws"
;
import
{
WebSocketServer
}
from
"ws"
;
const
notification_proxy
=
new
WebSocketServer
({
port
:
3001
});
let
notification_subs
=
[];
notification_proxy
.
on
(
'connection'
,
(
ws
)
=>
{
notification_subs
.
push
(
ws
);
});
export
function
send_notification
(
is_ok
,
context
,
message
)
{
let
updated_subs
=
[];
if
(
notification_subs
.
length
===
0
)
{
console
.
log
(
"WARNING: Got a notification, but nobody is subscribed"
);
}
for
(
const
sub
of
notification_subs
)
{
if
(
sub
.
readyState
==
WebSocket
.
CONNECTING
)
{
console
.
log
(
"WARNING: Unable to forward a notification to client that is still connecting"
);
updated_subs
.
push
(
sub
);
}
else
{
try
{
sub
.
send
(
JSON
.
stringify
({
is_ok
,
context
,
message
}));
updated_subs
.
push
(
sub
);
}
catch
{
sub
.
close
();
console
.
log
(
"WARNING: Fail to send a notification, closing the connection"
);
}
}
}
}
File Metadata
Details
Attached
Mime Type
application/javascript
Expires
Sat, Nov 28, 04:26 (1 d, 4 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1226577
Default Alt Text
notifications.mjs (906 B)
Attached To
Mode
R134 rentgen-android
Attached
Detach File
Event Timeline