@@ -37,8 +37,8 @@ app.listen(PORT, () => {
37
37
console . log ( `API Documentation: ${ SWAGGER_URL } ` ) ;
38
38
} ) ;
39
39
40
+ // Socket.io
40
41
const server = http . createServer ( app ) ;
41
-
42
42
const io = new Server ( server , {
43
43
cors : {
44
44
origin : "http://localhost:3000" ,
@@ -47,20 +47,18 @@ const io = new Server(server, {
47
47
} ) ;
48
48
49
49
server . listen ( 4001 , ( ) => {
50
- console . log ( `Server is listening at 4001` ) ;
50
+ console . log ( `Socket server is listening at port 4001` ) ;
51
51
} ) ;
52
52
53
53
let walletAddress = null ;
54
54
let listSharkFollowed = [ ] ;
55
55
56
56
io . on ( "connection" , async function ( socket ) {
57
- // console.log("Someone connected");
58
-
57
+ console . log ( "Someone connected" ) ;
59
58
socket . on ( "get-wallet-address" , async ( address ) => {
60
59
if ( address !== null ) {
61
60
walletAddress = address ;
62
61
console . log ( "global" , walletAddress ) ;
63
-
64
62
listSharkFollowed = await getListOfSharkFollowed ( walletAddress ) ;
65
63
}
66
64
} ) ;
@@ -74,14 +72,13 @@ InvestorModel.watch([
74
72
if ( walletAddress !== null ) {
75
73
for ( var shark of listSharkFollowed . datas ) {
76
74
const newTransactions = await getNewTransactions ( shark . sharkId ) ;
77
-
78
- if ( newTransactions . transactionsHistory . length > 0 ) {
75
+
76
+ if ( newTransactions . transactionsHistory . length > 0 ) {
79
77
io . emit ( "new-transactions" , {
80
78
newTransactions : newTransactions ,
81
79
sharkId : shark . sharkId
82
80
} ) ;
83
81
}
84
-
85
82
}
86
83
}
87
84
} ) ;
0 commit comments