Skip to main content

Ringing

The Call object provides several options to ring and notify users about a call.

Ringing

If a call was not created before, you should first create it and pass the ring value to true. For this, you can use the create method from the Call object.

let call = streamVideo.call(callType: "default", callId: callId)
let callResponse = try await call.create(members: members, ring: true)

When ring is true, a VoIP notification will be sent to the members, provided you have the required setup for CallKit and PushKit. If you don't have a VoIP push setup, a regular push notification will be sent to the members. For more details around push notifications, please check this page.

If ring is false, no push notification will be sent.

If a call was created before, the method will just get it and send the notifications. If you are sure that a call exists, you can use the get method instead:

let call = streamVideo.call(callType: "default", callId: callId)
let callResponse = try await call.get(ring: true)

Additionally, you can use the ring method which is just a shortcut for the method above:

let call = streamVideo.call(callType: "default", callId: callId)
let callResponse = try await call.ring()

Notifying users

In some cases, you just want to notify users that you joined a call, instead of ringing. To do this, you should use the notify option:

let call = streamVideo.call(callType: "default", callId: callId)
let callResponse = try await call.create(members: members, notify: true)

When notify is true, a regular push notification will be sent to all the members. This can be useful for livestreams apps or huddles.

Similarly to ringing, you can use the get method if you are sure that the call exists:

let call = streamVideo.call(callType: "default", callId: callId)
let callResponse = try await call.get(notify: true)

You can also use a shortcut of this method, with the notify method:

let call = streamVideo.call(callType: "default", callId: callId)
let callResponse = try await call.notify()

AutoLeave Policy

There may be scenarios where once a call is concluded there is no point for a user to remain in the call if the other participants have already left. In cases like that you may find youself in a position where you need to last participant to automatically leave the call. Luckily, the StreamVideoSwiftUI SDK makes that very easy by allowing you to set the ParticipantAutoLeavePolicy, like below:

let callViewModel = CallViewModel()
callViewModel.participantAutoLeavePolicy = LastParticipantAutoLeavePolicy()

By doing that, we are instructing the CallViewModel to observe the participants during the ringing flow call (incoming or outgoing). Once a user remain the last one, the callViewModel will automatically trigger the flow to leave the call.

note

The participantAutoLeavePolicy is set to DefaultParticipantAutoLeavePolicy which is a no-operation policy, meaning that if the user remain in the call alone, no automatic action will be performed.

Did you find this page helpful?