Repository navigation
London | 26-SDC-July | Raihan Sharif | Sprint 2 | Chat-app - #124
RaihanSharif wants to merge 50 commits into
Conversation
Can post message, with validation. Can get all messages.
Only return list of messages, or a single message. Clean up js doc
Messages can now be fetched or created using REST API. Client can then fetch subsequent messages using event streaming.
create new message handling function.
Event driven messages and reactions using both long polling and short polling
|
Updated long/short polling implementation to use event-driven architecture. This prevents race conditions where some reactions may not be sent to a client if they arrive in the gap between processing one request and sending another. Resulting in reactions on one client being behind another, until they refresh. |
new events are generated by POST HTTP requests. Events are broadcast to clients over WebSocket. Clients are given a snapshot when they first connect.
Websocket version only has websocket code, everything else is in a separate file that can be reused by polling version.
Extract common code for the web socket and polling versions.
|
Update: I have now created the two separate apps, one polling and one Websocket. Both try to reuse as much code as possible, both in the frontend and backend. Backend:
Frontend:
Application uses HTTP post to create new messages and reactions and event streaming through either long polling or websocket to read new events. Has some functionality to avoid race conditions by using even cursor per client. |
|
The files changed in this PR don't match what is expected for this task. Please check that you committed the right files for the task, and that there are no accidentally committed files from other sprints. Please review the 'files changed' tab at the top of the page. Here is an example of a file that has been changed on this branch but shouldn't be: If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). If this PR needs reviewed, please add the 'Needs Review' label to this PR after you have resolved the issues listed above. |
LonMcGregor
left a comment
There was a problem hiding this comment.
Good work building this app, you've organised the files neatly and used classes where appropriate. I can also see places where you've given consideration to how you could extend with new functionality later.
I have spotted a few areas where you could improve, or where you could answer my questions to check your understanding of the code.
| @@ -0,0 +1,3 @@ | |||
| { | |||
| "githubPullRequests.ignoredPullRequestBranches": ["main"] | |||
There was a problem hiding this comment.
If these are just settings for your own machine, you shouldn't commit them to a PR. Is that the case here?
| const msg_body = document.getElementById("message-input").value; | ||
|
|
||
| try { | ||
| await chatRequest(`${BACKEND_URL}/messages`, { |
There was a problem hiding this comment.
If you are using the socket based app, does sendMessage have any way of using the socket, or does it end up making extra requests?
| @@ -0,0 +1,17 @@ | |||
| export class Message { | |||
| static #nextId = 0; | |||
There was a problem hiding this comment.
Can you explain what the static keyword here means?
| } | ||
|
|
||
| /** | ||
| * Adds an event to the event stream. {sequnce, type, timestamp, data}. |
There was a problem hiding this comment.
Good use of documentation comments
| /** | ||
| * Sends new events for each waiting request, if there are any events to send. | ||
| */ | ||
| notifyWaiters() { |
There was a problem hiding this comment.
What is the difference between a "waiter" and a "subscriber"?
|
The files changed in this PR don't match what is expected for this task. Please check that you committed the right files for the task, and that there are no accidentally committed files from other sprints. Please review the 'files changed' tab at the top of the page. Here is an example of a file that has been changed on this branch but shouldn't be: If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). If this PR needs reviewed, please add the 'Needs Review' label to this PR after you have resolved the issues listed above. |
1 similar comment
|
The files changed in this PR don't match what is expected for this task. Please check that you committed the right files for the task, and that there are no accidentally committed files from other sprints. Please review the 'files changed' tab at the top of the page. Here is an example of a file that has been changed on this branch but shouldn't be: If this PR is not coursework, please add the NotCoursework label (and message on Slack in #cyf-curriculum or it will probably not be noticed). If this PR needs reviewed, please add the 'Needs Review' label to this PR after you have resolved the issues listed above. |
Learners, PR Template
Self checklist
Task code
CYF-1162
Changelist
Created a live updating chat app that allows client to use either long polling or short polling.
Users can add new message
User is notified whenever a new message is created by another user
User can like or dislike a message
User is notified when a message is liked/disliked
backend: https://z4k2yzxetkpevkwf6zy9ea37.trainees.hosting.cyf.academy/messages
frontend: https://qhdyqohwxffxraktvwh1e0ys.trainees.hosting.cyf.academy/