socrits 0.1.0
socrits: ^0.1.0 copied to clipboard
Socrits SDK for Flutter - video & voice calls, call invitations (ring/accept), and in-app chat. Drop-in prebuilt UI kit plus a low-level core client.
socrits — Flutter SDK #
Call invitations (signalling) + audio/video calls on your self-hosted Socrits. A drop-in replacement for ZEGO's call-invitation + prebuilt-call stack — same concepts, your infrastructure.
Install #
dependencies:
socrits:
path: ../suryacloud/sdk/flutter # or a git/pub ref once published
Usage #
final sc = Socrits(baseUrl: 'https://api.socrits.example');
// your backend mints the user token via POST /v1/session (API key stays server-side)
await sc.connect(sessionEndpoint: 'https://your-backend/sc-session', userId: 'alice');
// a ring arrives → show your incoming-call UI
sc.onIncomingCall = (call) {
// call.fromUserName, call.mode …
// sc.accept(call); or sc.reject(call);
};
// call connected → render the media room with the prebuilt call UI
sc.onCallConnected = (room, mode) {
Navigator.push(context, MaterialPageRoute(builder: (_) => Scaffold(
body: SocritsCallView(room: room, onHangUp: () => Navigator.pop(context)),
)));
};
sc.onCallRejected = (callId) {}; // ZEGO onOutgoingCallDeclined
sc.onCallEnded = (reason) {}; // 'timeout' (no answer) | 'cancelled'
// place a call
final callId = await sc.invite(toUserId: 'bob', mode: CallMode.video);
// in-call data (e.g. the coin/minute balance sync)
sc.sendData('bob', callId, {'coin_balance': 120});
sc.onData = (from, data) { /* … */ };
Mapping from ZEGO #
| ZEGO (dating app used this) | Socrits SDK |
|---|---|
ZegoUIKitPrebuiltCallInvitationService().send(...) |
sc.invite(toUserId: ..., mode: ...) |
onIncomingCall (ring) |
sc.onIncomingCall |
accept() |
sc.accept(call) → joins the LiveKit room |
onOutgoingCallDeclined |
sc.onCallRejected |
onOutgoingCallTimeout |
sc.onCallEnded('timeout') |
sendInRoomCommand(...) |
sc.sendData(...) |
| appID + appSign (client secret) | server-minted token — no secret in the app |
Prebuilt call UI #
SocritsCallView(room: room) is a drop-in call screen — video grid + mic /
camera / hang-up controls (the ZegoUIKitPrebuiltCall equivalent). Or render
the room yourself with livekit widgets.
Native ringing (offline / CallKit) #
So a call rings on a locked phone with the app closed:
- Register the device after connecting:
final fcmToken = await FirebaseMessaging.instance.getToken(); sc.registerDevice(fcmToken!); // stored server-side per user - Socrits pushes an
incoming_callFCM data message when the callee is offline (setFCM_SERVICE_ACCOUNTon the server to enable real sends). - In your FCM background handler, show native UI with
flutter_callkit_incoming; on accept,connect()andaccept(call)to join.
The push payload carries callId, room, mode, fromUserId, fromUserName.