How to send message like whatsapp, telgram, viber or imo just between two person?
See original GitHub issueHi, I want to create a messenger app like whatsapp,
- First I need to make a list of people connected to my messenger app.
- I want to message to one of the person which existed on the list, so I click on its name on the list.
- Now I want to chat with him.
Here I dont want message gets broadcast to all people.
So please show me the best secure way.
I’ve done some like below code. I am just created a room only between two person this works well. but problem is when two person for the first time and the same time click each other to go messaging there two diffrent rooms gets create. if they click each other from the list for the first time in different time then it works well.
(async () => {
try {
const r1 = await AsyncStorage.getItem(userphone + "u-uuuuuuuu-u" + mynumber);
const r2 = await AsyncStorage.getItem(mynumber + "u-uuuuuuuu-u" + userphone);
if (r1 !== null || r2 !== null) {
if (r1 !== null) {
this.socket.emit("joiningroom", { room: r1 });
if (this._isMounted) {
this.setState({ room: r1 });
}
} else {
this.socket.emit("joiningroom", { room: r2 });
if (this._isMounted) {
this.setState({ room: r2 });
}
}
} else {
var ref1 = db.collection('chatrooms').doc(userphone + "u-uuuuuuuu-u" + mynumber);
var ref2 = db.collection('chatrooms').doc(mynumber + "u-uuuuuuuu-u" + userphone);
const doc1 = await ref1.get();
const doc2 = await ref2.get();
if (doc1.exists || doc2.exists) {
if (doc1.exists) {
const room = doc1.data().mbaliotaq;
this.socket.emit("joiningroom", { room });
if (this._isMounted) {
this.setState({ room });
}
await AsyncStorage.setItem(userphone + "u-uuuuuuuu-u" + mynumber, room);
} else {
const room = doc2.data().mbaliotaq;
this.socket.emit("joiningroom", { room });
if (this._isMounted) {
this.setState({ room });
}
await AsyncStorage.setItem(mynumber + "u-uuuuuuuu-u" + userphone, room);
}
} else {
const id = userphone + "u-uuuuuuuu-u" + mynumber;
const room = "mmm" + userphone + "r-rrrrrrrrr-r" + mynumber + "mmm";
db.collection('chatrooms').doc(id).set({
mbaliotaq: room
}).then(() => {
this.socket.emit("joiningroom", { room });
if (this._isMounted) {
this.setState({ room });
}
}).catch(err => {
console.log(err);
});
}
}
} catch (e) {
console.log(`Error in async ${e}`);
}
})();
I need a bettter way and a secure way than my solution.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
How to send message like whatsapp, telegram, viber or imo ...
I am just created a room only between two person this works well. but problem is when two person for the first time...
Read more >Top 10 WhatsApp Alternative Apps You Can Use - Beebom
Like WhatsApp, Viber lets you make video and voice calls but the app goes one step ahead with its Viber Out feature, which...
Read more >12 Most Used Messaging Apps - Engadget
12 Most Used Messaging Apps · 1. Messenger · 2. WhatsApp Messenger · 3. WeChat · 4. Line · 5. Viber · 6....
Read more >The 5 best texting apps in 2022 - Zapier
While many other apps include voice messaging (like WhatsApp, above), Viber makes it just as easy to send a video message for a...
Read more >Viber - Safe Chats And Calls - Apps on Google Play
Viber is a secure, private, fun messaging and calling app, connecting over a billion people worldwide! With group chats, disappearing messages, reminders, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For future readers:
Please see the example here: https://socket.io/get-started/private-messaging-part-1/
I am not an expert but I think they using p2p connection. Look for something like dat://