-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1776 from Giveth/feat/stellar_integration
fix: reduce timer to 15 mins & update renew draft donation expiration…
- Loading branch information
Showing
6 changed files
with
159 additions
and
31 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import WebSocket from 'ws'; | ||
import { logger } from '../../utils/logger'; | ||
|
||
export function startWebSocketServer(server) { | ||
const wss = new WebSocket.Server({ server }); | ||
|
||
// Handle WebSocket connections | ||
wss.on('connection', ws => { | ||
ws.on('message', message => { | ||
logger.info(`Received message: ${message}`); | ||
}); | ||
}); | ||
|
||
// Broadcast a message to all connected clients | ||
function broadcastMessage(message) { | ||
wss.clients.forEach(client => { | ||
if (client.readyState === WebSocket.OPEN) { | ||
client.send(message); | ||
} | ||
}); | ||
} | ||
|
||
// Exported function to be called from cron job | ||
function notifyDonationAdded(donation) { | ||
const message = JSON.stringify({ | ||
type: 'new-donation', | ||
data: donation, | ||
}); | ||
broadcastMessage(message); | ||
} | ||
|
||
// Exported function to to be called when marking draft donation as failed | ||
function notifyDraftDonationFailed(donation) { | ||
const message = JSON.stringify({ | ||
type: 'draft-donation-failed', | ||
data: donation, | ||
}); | ||
broadcastMessage(message); | ||
} | ||
|
||
// Export the notifyDonationAdded function so it can be used externally | ||
return { | ||
notifyDonationAdded, | ||
notifyDraftDonationFailed, | ||
}; | ||
} |