0% found this document useful (0 votes)
13 views4 pages

Flutter SocketIO Guide

This document provides instructions for integrating Socket.IO for chat, voice, and video functionalities in a Flutter application. It outlines the connection and authentication process, various events for chat, voice, and video calls, as well as disconnect handling and push notifications. A summary of socket events and their corresponding responses is also included to facilitate implementation.

Uploaded by

Abhijeet Das
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views4 pages

Flutter SocketIO Guide

This document provides instructions for integrating Socket.IO for chat, voice, and video functionalities in a Flutter application. It outlines the connection and authentication process, various events for chat, voice, and video calls, as well as disconnect handling and push notifications. A summary of socket events and their corresponding responses is also included to facilitate implementation.

Uploaded by

Abhijeet Das
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

📘 Flutter Developer Instruction

Document
Socket.IO Integration for Chat, Voice & Video

1. Connect & Authenticate


Connect to Socket:

final socket = IO.io("https://your-server.com", {


"transports": ["websocket"],
"autoConnect": false,
});
socket.connect();

Emit after connection:

socket.emit("userConnect", { "token": "<JWT_TOKEN>" });


socket.emit("expertConnect", { "token": "<JWT_TOKEN>" });

No direct response — required to use the socket

2. Chat Events
chatRequest (User → Expert)

socket.emit("chatRequest", {
"userId": "USER_ID",
"expertId": "EXPERT_ID"
});

Receive: chatWaiting or paidChatInvalid

chatAccept (Expert)
socket.emit("chatAccept", {
"expertId": "EXPERT_ID",
"userId": "USER_ID"
});

Receive: chatStarted { chatId, maxMinutes, userId, expertId }

sendMessage

socket.emit("sendMessage", {
"chatId": "CHAT_ID",
"senderId": "USER_OR_EXPERT_ID",
"content": "Hello"
});

Receive: receiveMessage

endChat

socket.emit("endChat", { "chatId": "CHAT_ID" });

Receive: chatEnded

3. Voice Call Events


voiceCallRequest

socket.emit("voiceCallRequest", {
"userId": "USER_ID",
"expertId": "EXPERT_ID"
});

Receive: callWaiting or callInvalid

voiceCallAccept
socket.emit("voiceCallAccept", {
"expertId": "EXPERT_ID",
"userId": "USER_ID"
});

Receive: voiceCallStarted

voiceCallEnd

socket.emit("voiceCallEnd", { "callId": "CALL_ID" });

Receive: callEnded

4. Video Call Events


videoCallRequest

socket.emit("videoCallRequest", {
"userId": "USER_ID",
"expertId": "EXPERT_ID"
});

Receive: callWaiting or callInvalid

videoCallAccept

socket.emit("videoCallAccept", {
"expertId": "EXPERT_ID",
"userId": "USER_ID"
});

Receive: videoCallStarted

callEnd
socket.emit("callEnd", { "callId": "CALL_ID" });

Receive: callEnded

5. Disconnect Handling
After 30s of no reconnection, the server ends chat or call and emits:

{ chatEnded or callEnded, reason: "User/Expert disconnected (30s


timeout)" }

6. Push Notifications
Sent to Expert when user sends a request:

{
"for": "chat" | "voice" | "video",
"name": "User Name",
"userId": "...",
"expertId": "...",
"userSocketId": "..."
}

7. Socket Event Summary


Emit Event Response Event Purpose
userConnect — Authenticate user
expertConnect — Authenticate expert
chatRequest chatWaiting / Request chat
paidChatInvalid
chatAccept chatStarted Start chat
sendMessage receiveMessage Send chat message
endChat chatEnded End chat
voiceCallRequest callWaiting / callInvalid Request voice call
voiceCallAccept voiceCallStarted Start voice call
voiceCallEnd callEnded End voice call
videoCallRequest callWaiting / callInvalid Request video call
videoCallAccept videoCallStarted Start video call
callEnd callEnded End video call

You might also like