Browse SDKs · iOS
SDKsiOSEnterprise

Handle call events

Add and remove the OpenIM iOS SDK call signaling delegate in one place.

Copy

Implement a stable OIMSignalingListener in the call state layer, and use the same instance when adding and removing it:

@interface CallStore () <OIMSignalingListener>
@end

@implementation CallStore

- (void)startListening {
    [[OIMManager callbacker] addSignalingListener:self];
}

- (void)stopListening {
    [[OIMManager callbacker] removeSignalingListener:self];
}

- (void)onReceiveNewInvitation:(OIMSignalingInfo *)info {
    [self upsertCall:info state:@"ringing"];
}
- (void)onInviteeAccepted:(OIMSignalingInfo *)info { [self mergeCall:info state:@"accepted"]; }
- (void)onInviteeRejected:(OIMSignalingInfo *)info { [self mergeCall:info state:@"rejected"]; }
- (void)onInvitationCancelled:(OIMSignalingInfo *)info { [self finishCall:info.invitation.roomID]; }
- (void)onInvitationTimeout:(OIMSignalingInfo *)info { [self finishCall:info.invitation.roomID]; }
- (void)onInviteeAcceptedByOtherDevice:(OIMSignalingInfo *)info { [self stopRinging:info.invitation.roomID]; }
- (void)onInviteeRejectedByOtherDevice:(OIMSignalingInfo *)info { [self stopRinging:info.invitation.roomID]; }
- (void)onHunguUp:(OIMSignalingInfo *)info { [self finishCall:info.invitation.roomID]; }
- (void)onRoomParticipantConnected:(OIMParticipantConnectedInfo *)info {
    [self mergeParticipants:info roomID:info.roomID];
}
- (void)onRoomParticipantDisconnected:(OIMParticipantConnectedInfo *)info {
    [self removeParticipants:info roomID:info.roomID];
}
- (void)onStreamChange:(OIMMeetingStreamEvent *)event {
    [self updateStream:event roomID:event.roomID];
}

@end

This is the only page that owns complete examples for the call delegates above. Merge events by roomID, and use the user ID as well for participant state. Call removeSignalingListener: when the user logs out or switches accounts, or when the call state layer is destroyed.