Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F7862391
biz-server.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
biz-server.js
View Options
var
config
=
require
(
"prometheus-config"
);
var
biz_access
=
require
(
"prometheus-biz-accessor"
);
var
io
=
require
(
'socket.io'
)();
// utworzenie servera
io
.
listen
(
config
.
biz_layer_config
.
port
);
console
.
log
(
"###############\n Socket.io started on port "
+
config
.
biz_layer_config
.
port
+
"\n###############"
);
/********************************
POŁĄCZNIE Z WARSTWĄ WEBOWĄ
*********************************/
// nowe połącznie
io
.
on
(
'connection'
,
function
(
socket
)
{
console
.
log
(
"# A client connected!!"
);
socket
.
on
(
'hello_server'
,
function
(
data
)
{
global
.
user
=
data
.
params
;
console
.
log
(
global
[
data
.
method
](
data
.
params
));
//greetings from client
//Wysyłanie do wszystkich (z wyjątkiem użytkownika, który się podłączył)
socket
.
broadcast
.
emit
(
'notification'
,
{
method
:
"getNotification"
,
params
:
"User "
+
user
+
"właśnie dołączył do biz."
,
id
:
1
});
});
socket
.
emit
(
"hello_client"
,
{
method
:
"greetings"
,
params
:
"Brawo! Połączyłeś się z warstwą biznesową."
,
id
:
1
});
socket
.
on
(
"service_event"
,
function
(
data
){
var
service_name
=
data
.
service_name
;
var
event_name
=
data
.
event_name
;
var
payload
=
data
.
payload
;
var
request_id
=
data
.
request_id
;
biz_access
.
emit_service_event
(
service_name
,
event_name
,
payload
,
function
(
data
){
var
data_to_send
=
{};
data_to_send
.
request_id
=
request_id
;
data_to_send
.
payload
=
data
;
socket
.
emit
(
"service_event_response"
,
data_to_send
);
//console.log("response emitted with event service_event_response:", data_to_send);
});
});
//event wylogowania
socket
.
on
(
'logout'
,
function
(){
socket
.
disconnect
();
// zamknięcie połączenia
});
socket
.
on
(
'disconnect'
,
function
()
{
console
.
log
(
"User disconnected"
);
// event rozłączenia
});
});
global
.
greetings
=
function
(
data
)
{
return
"New user connected: "
+
data
+
", sending greetings..."
;
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Aug 13, 20:27 (1 d, 1 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
868222
Default Alt Text
biz-server.js (2 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment