Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F10361082
notifications.mjs
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
942 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
text/x-java
Expires
Sat, Nov 8, 10:58 (18 h, 23 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1034492
Default Alt Text
notifications.mjs (942 B)
Attached To
Mode
R134 rentgen-android
Attached
Detach File
Event Timeline
Log In to Comment