-
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 #1780 from Giveth/feat/stellar_integration
fix: change from WS to SSE
- Loading branch information
Showing
7 changed files
with
68 additions
and
64 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,45 @@ | ||
import { Response } from 'express'; | ||
|
||
let clients: Response[] = []; | ||
type TNewDonation = { | ||
type: 'new-donation'; | ||
data: { | ||
donationId: number; | ||
draftDonationId: number; | ||
}; | ||
}; | ||
|
||
type TDraftDonationFailed = { | ||
type: 'draft-donation-failed'; | ||
data: { | ||
draftDonationId: number; | ||
expiresAt?: Date; | ||
}; | ||
}; | ||
|
||
// Add a new client to the SSE stream | ||
export function addClient(res: Response) { | ||
res.setHeader('Access-Control-Allow-Origin', '*'); | ||
res.setHeader('Content-Type', 'text/event-stream'); | ||
res.setHeader('Cache-Control', 'no-cache'); | ||
res.setHeader('Connection', 'keep-alive'); | ||
|
||
res.flushHeaders(); | ||
|
||
clients.push(res); | ||
|
||
// Remove the client on disconnect | ||
res.on('close', () => { | ||
clients = clients.filter(client => client !== res); | ||
}); | ||
} | ||
|
||
// Notify all connected clients about a new donation | ||
export function notifyClients(data: TNewDonation) { | ||
clients.forEach(client => client.write(`data: ${JSON.stringify(data)}\n\n`)); | ||
} | ||
|
||
// Notify all connected clients about a failed donation | ||
export function notifyDonationFailed(data: TDraftDonationFailed) { | ||
clients.forEach(client => client.write(`data: ${JSON.stringify(data)}\n\n`)); | ||
} |
This file was deleted.
Oops, something went wrong.