This guide explains how to use the Fluxer API for calls, voice channels, and real-time features.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Fluxer Mobile App β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β API Service β β WebSocket β β Call Service β β
β β (REST) β β (Gateway) β β (CallKit) β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Fluxer Platform β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β HTTP API β β Gateway β β Voice SFU β β
β β api.fluxer β β WebSocket β β WebRTC β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Handles all REST API calls to Fluxer:
// Get singleton
let api = APIService.shared
// Set auth token (after login)
api.setAuthToken("your_bearer_token")
// Make API calls
do {
let user = try await api.getCurrentUser()
let guilds = try await api.getUserGuilds()
} catch {
print("API Error: \(error)")
}Manages real-time connection to Fluxer Gateway:
// Get singleton
let ws = WebSocketService.shared
// Connect with auth token
ws.connect(token: "your_token")
// Set up event handlers
ws.onMessageCreate = { message in
// Handle new message
}
ws.onCallCreate = { call in
// Handle incoming call
}Manages calls using CallKit + Fluxer API:
// Get singleton
let callService = FluxerCallService.shared
// Configure with API and WebSocket
callService.configure(
apiService: apiService,
webSocketService: webSocketService
)
// Start a call
try await callService.startCall(
channelId: "channel_id",
type: .voice // or .video
)
// Answer incoming call
try await callService.answerCall()
// End call
try await callService.endCall()1. Push Notification (APNs)
β
2. PushNotificationService.handleIncomingCall()
β
3. FluxerCallService.reportIncomingCall() β CallKit
β
4. User answers β CallKit callback
β
5. API: POST /calls/{id}/accept
β
6. API: GET /channels/{id}/voice-token
β
7. Connect to Fluxer Voice Gateway (WebRTC)
β
8. Call connected!
1. User initiates call
β
2. API: POST /channels/{id}/calls
β
3. CallKit: Start outgoing call UI
β
4. API: GET /channels/{id}/voice-token
β
5. Connect to Fluxer Voice Gateway
β
6. Remote user answers
β
7. Call connected!
let callService = FluxerCallService.shared
// Join voice channel
try await callService.joinVoiceChannel("channel_id")
// Now you're in the voice channel
// - Other participants can see you
// - You can hear others
// - You can enable video/mute// Mute/unmute
try await callService.toggleMute()
// Deafen/undeafen
callService.toggleDeafen()
// Enable/disable video (DM calls only)
try await callService.toggleVideo()
// Leave channel
await callService.leaveVoiceChannel()// Start screen share
try await callService.startScreenSharing()
// Shows system broadcast picker
// Stop screen share
try await callService.stopScreenSharing()webSocketService.onMessageCreate = { message in
// New message received
// Update UI, play sound
}
webSocketService.onMessageUpdate = { message in
// Message edited
}
webSocketService.onMessageDelete = { messageId in
// Message deleted
}webSocketService.onTypingStart = { event in
// User started typing
// Show "Alice is typing..."
}webSocketService.onCallCreate = { call in
// Incoming call
// Show call UI
}
webSocketService.onCallUpdate = { call in
// Call state changed
}
webSocketService.onCallDelete = { callId in
// Call ended
}webSocketService.onVoiceStateUpdate = { voiceState in
// User joined/left/muted in voice channel
}
webSocketService.onSpeaking = { userId, speaking in
// Update speaking indicator
}POST /auth/login- Get bearer tokenPOST /users/@me/devices- Register push token
GET /users/@me- Current userGET /users/@me/guilds- User's servers
GET /channels/{id}- Channel infoGET /channels/{id}/messages- MessagesPOST /channels/{id}/messages- Send messageGET /channels/{id}/voice-token- Get voice token
POST /channels/{id}/calls- Create callPOST /calls/{id}/accept- Accept callDELETE /calls/{id}- End callPATCH /calls/{id}/state- Update call statePOST /calls/{id}/screen-share- Start screen shareDELETE /calls/{id}/screen-share- Stop screen share
// 1. Login via API
let response = try await apiService.login(
instance: "fluxer.app",
username: "user",
password: "pass"
)
// 2. Store token
apiService.setAuthToken(response.token)
// 3. Connect WebSocket
webSocketService.connect(token: response.token)
// 4. Register for push notifications
let deviceToken = ... // From APNs
await apiService.registerDeviceToken(token: deviceToken)The API service automatically handles 401 errors. Your app should:
- Detect 401 response
- Refresh token via
POST /auth/refresh - Retry the failed request
Simulator can't do real calls, but you can test UI:
// Simulate incoming call
let mockCall = FluxerCall(
id: "123",
channelId: "456",
guildId: nil,
initiator: User.preview,
participants: [],
type: .voice,
status: .ringing,
startedAt: Date(),
endedAt: nil
)
FluxerCallService.shared.activeCall = mockCall- Build to physical device
- Join voice channel
- Test with another user on web/desktop
- Start call
- Tap screen share button
- Select "FluxerBroadcastExtension"
- Tap "Start Broadcast"
- Other participants see your screen
- APIService setup
- WebSocketService setup
- Authentication flow
- Error handling & retry
- Token refresh
- Send/receive messages
- Typing indicators
- Read receipts
- File uploads (including voice messages)
- Message reactions
- CallKit integration
- Incoming calls
- Outgoing calls
- Voice connection (WebRTC)
- Video support
- Screen sharing
- Join/leave channels
- Participant list
- Mute/deafen
- Speaking indicators
- Video in voice channels
- Screen share in voice channels
-
Add WebRTC Framework
- Google WebRTC or Amazon Kinesis
- Implement in VoiceConnection class
-
Handle Reconnection
- Network drops
- App background/foreground
- WebSocket reconnect
-
Optimize Performance
- Lazy loading messages
- Image caching
- Voice codec selection
-
Add Tests
- Unit tests for services
- UI tests for call flow
- Network mocking
For Fluxer Mobile Client