Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I_Helmet
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
21_22-J 62
I_Helmet
Commits
485734fe
Commit
485734fe
authored
Jul 03, 2022
by
Balasuriya D.A.M.
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Realtime Messages Front/Back
parent
c80391ca
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
6 deletions
+36
-6
IT18021080/Telemedicine-Chat-App/backend/server.js
IT18021080/Telemedicine-Chat-App/backend/server.js
+12
-0
IT18021080/Telemedicine-Chat-App/frontend/src/components/SingleChat.js
...lemedicine-Chat-App/frontend/src/components/SingleChat.js
+24
-6
No files found.
IT18021080/Telemedicine-Chat-App/backend/server.js
View file @
485734fe
...
@@ -58,6 +58,18 @@ io.on("connection", (socket) => {
...
@@ -58,6 +58,18 @@ io.on("connection", (socket) => {
console
.
log
(
"
User Joined Room:
"
+
room
);
console
.
log
(
"
User Joined Room:
"
+
room
);
});
});
socket
.
on
(
"
new message
"
,
(
newMessageRecieved
)
=>
{
var
chat
=
newMessageRecieved
.
chat
;
if
(
!
chat
.
users
)
return
console
.
log
(
"
chat.users not defined
"
);
chat
.
users
.
forEach
(
user
=>
{
if
(
user
.
_id
==
newMessageRecieved
.
sender
.
_id
)
return
;
socket
.
in
(
user
.
_id
).
emit
(
"
message recieved
"
,
newMessageRecieved
);
});
});
});
});
...
...
IT18021080/Telemedicine-Chat-App/frontend/src/components/SingleChat.js
View file @
485734fe
...
@@ -63,10 +63,32 @@ const SingleChat = ({ fetchAgain, setFetchAgain }) => {
...
@@ -63,10 +63,32 @@ const SingleChat = ({ fetchAgain, setFetchAgain }) => {
console
.
log
(
messages
);
console
.
log
(
messages
);
useEffect
(()
=>
{
socket
=
io
(
ENDPOINT
);
socket
.
emit
(
"
setup
"
,
user
);
socket
.
on
(
"
connection
"
,
()
=>
setSocketConnected
(
true
));
},
[]);
useEffect
(()
=>
{
useEffect
(()
=>
{
fetchMessages
();
fetchMessages
();
selectedChatCompare
=
selectedChat
;
},
[
selectedChat
]);
},
[
selectedChat
]);
useEffect
(()
=>
{
socket
.
on
(
"
message recieved
"
,
(
newMessageRecieved
)
=>
{
if
(
!
selectedChatCompare
||
selectedChatCompare
.
_id
!==
newMessageRecieved
.
chat
.
_id
)
{
//give notification
}
else
{
setMessages
([...
messages
,
newMessageRecieved
]);
}
});
});
const
sendMessage
=
async
(
event
)
=>
{
const
sendMessage
=
async
(
event
)
=>
{
if
(
event
.
key
===
"
Enter
"
&&
newMessage
)
{
if
(
event
.
key
===
"
Enter
"
&&
newMessage
)
{
try
{
try
{
...
@@ -90,7 +112,7 @@ const SingleChat = ({ fetchAgain, setFetchAgain }) => {
...
@@ -90,7 +112,7 @@ const SingleChat = ({ fetchAgain, setFetchAgain }) => {
console
.
log
(
data
);
console
.
log
(
data
);
socket
.
emit
(
"
new message
"
,
data
);
setMessages
([...
messages
,
data
]);
setMessages
([...
messages
,
data
]);
}
catch
(
error
)
{
}
catch
(
error
)
{
toast
({
toast
({
...
@@ -105,11 +127,7 @@ const SingleChat = ({ fetchAgain, setFetchAgain }) => {
...
@@ -105,11 +127,7 @@ const SingleChat = ({ fetchAgain, setFetchAgain }) => {
}
}
};
};
useEffect
(()
=>
{
socket
=
io
(
ENDPOINT
);
socket
.
emit
(
"
setup
"
,
user
);
socket
.
on
(
"
connection
"
,
()
=>
setSocketConnected
(
true
));
},
[]);
const
typingHandler
=
(
e
)
=>
{
const
typingHandler
=
(
e
)
=>
{
setNewMessage
(
e
.
target
.
value
);
setNewMessage
(
e
.
target
.
value
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment