Closed pwFoo closed 5 years ago
Sure, you can implement online/offline status by using the websocket connection status to the signalling server. You're right that you can't use WebRTC to show this kind of information (you must be connected already to know anything about peers through WebRTC).
Server:
const offlinePeers = {}
const onlinePeers = {}
signal.on('discover', (request) => {
const peerID = request.socket.id // use socket.id or whatever peer IDs
delete offlinePeers[peerID]
onlinePeers[peerID] = true
request.discover(peerID, { online: Object.keys(onlinePeers), offline: Object.keys(offlinePeers) })
request.socket.on('disconnect', () => { // when the socket disconnects, list the peer as "offline"
delete onlinePeers[peerID]
offlinePeers[peerID] = true
})
})
Client:
signalClient.addListener('discover', (discoveryData) => {
discoveryData.online // online peers
discoveryData.offline // offline peers
})
I should be able to add a full example of this sometime soon.
If you want to be able to send messages to offline peers, you could either send them to the websocket server and have the user request them when they're back online (like a traditional messaging app). simple-signal
doesn't have much to do with this, but socket.io
is very useful here.
If you want to only send messages via WebRTC, it gets trickier. You could connect a bunch of peers and have them "replicate" a log of messages. I can do a basic example of this too.
My idea is more a messenger (WhatsApp, Telegram, Hangout) instead of a "simple" chat (write with online and connected users only)... I know that's maybe to much to start with, but before I start I would be sure what is possible and what not / to complicated.
Text messages, audio / video calls and transfer files should be possible with webrtc / simple-peer. Signaling could be done with simple-signal. So I need to check how complicate features
That's why I searching libs / frameworks like simple-peer, simple-signal, signalhub, ...
If you want to only send messages via WebRTC, it gets trickier. You could connect a bunch of peers and have them "replicate" a log of messages. I can do a basic example of this too.
You mean without server, but replicate to peers would move from a central server to a unknown peer / client? Instead of replicate to clients I think a server (optional with encryption) to store messages would be better.
But another problem could be multiple clients (desktop, mobile) or push notifications (webpush api, but maybe also a server part needed client -> server -> vendor push service -> client).
So instead of a "small" basic project which could be extended it looks like a very big project and redundant to projects like nextcloud talk, matrix or tinode (Go based xmpp alternative in early development).
First asked that in wetrtc topic, but maybe more signaling related like session initialization? So I ask it here, @t-mullen :)
I searched and read some information about webrtc and maybe would start to play with webrtc (simple-peer, simple-signal)...
During think about it I stumbled over user online / offline presence and read by recipient information. Is it possible to implement such features and how could it be done?
I think webrtc connection is started on demand (chat, audio call offer). Send+Receive text message could be verified by data channel of both others are online, but if one user is offline (or just not "active" in the chat session = no webrtc connection established) webrtc data channel isn't established, right? So how could it done?