Skip to content

Group Call

adamrangs edited this page Aug 8, 2022 · 1 revision
  1. Use the webex.rooms.create API to create a Room.

    webex.rooms.create(title: "Hello World") { response in
        switch response.result {
        case .success(let room):
            // ...
        case .failure(let error):
            // ...
        }
    }
  2. Use the webex.memberships.create API to add people to the Room.

    webex.memberships.create(roomId: roomId, personEmail: email) { response in
        switch response.result {
        case .success(let membership):
            // ...
        case .failure(let error):
            // ...
        }
    }
  3. Dial a room by room id to make a group call with all peoples in the room.

    webex.phone.dial(room.id, option: MediaOption.audioVideo(local: ..., remote: ...)) { ret in
        switch ret {
        case .success(let call):
            call.onConnected = {
                // This method is invoked on successful completion of connect.
            }
            call.onDisconnected = { reason in
                // ...
            }
            call.onCallMembershipChanged = { changed in
                switch changed {
                case .joined(let membership):
                    // A remote participant accept the call and connects to the Room.
                case .left(let membership):
                    // A remote participant hangup the call and leaves from the Room.
                default:
                    //
                }                
            }            
        case .failure(let error):
            // failure
        }
    }
  4. In order to get the event of a participant in the call, the callback function onCallMembershipChanged is used.

    call.onCallMembershipChanged = { changed in
        switch changed {
        case .joined(let membership):
            print("The \(membership.email) accept the call and joins to the Room")
        case .left(let membership):
            print("The \(membership.email) hangup the call and leaves to the Room")
        case .declined(let membership):
            print("The \(membership.email) decline the call")
        case .sendingAudio(let membership):
            print("The \(membership.email) \(membership.sendingAudio ? "unmute" : "mute") voice")
        case .sendingVideo(let membership):
            print("The \(membership.email) \(membership.sendingVideo ? "unmute" : "mute") video")
        case .sendingScreenShare(let membership):
            print("The \(membership.email) \(membership.sendingScreenShare ? "start" : "stop") screen sharing")
        }
    }