Conversation

Here is a description of the different steps to create a multi-party communication:

Define the HTML structure

        <div id="conference">
        <div id="remote-container"></div>
        <div id="local-container"></div>
        </div>
    

Create and register a UserAgent

Check our tutorial on registration if needed to create the userAgent and register.

Create the conversation

        do {
            conversation = try session.getOrCreateConversation(name: conversationId)
        }
        catch {
            showError(error)
            return
        }
    

Create a stream

Check our tutorial on stream management to create the stream.

Join the conversation :

        conversation?.join(completion: { (error, accessAllowed) in
            if let error = error {
                showError(error)
                return
            }
            switch accessAllowed {
            case true:
                showMessage("Access allowed")
            case false:
                showMessage("Access denied")
            }
        })
    

Publish your stream to the conversation

Publish your stream thanks to the publish() function :

        conversation.publish(stream: stream) { (error, stream) in
            if let error = error {
                showError(error)
                return
            }
        }
    

Add events listeners on Conversation

Add listener on 'streamListChanged' event in order to subscribe to remote stream

'streamListChanged' Event gives the information about streams that are already published by remote parties on the conversation with the status : 'added', 'updated', 'removed'

You can then decide the streams you want to subscribe

        conversation?.onEvent(self, { (event) in
            switch event {
            case .streamListChanged(let type, let info):
                switch type {
                case .added:
                    if !self.streamList.contains(info.streamId) && info.isRemote {
                        self.subscribeToStreamWithId(info.streamId)
                    }
                case .removed:
                    handleStreamRemoving(info.streamId)
                default:
                    break
            }
            default:
                break
            }
        })
    

Add listener on 'streamAdded' and on 'streamRemoved' event in order to manage media element addings or removal in DOM

        conversation?.onEvent(self, { (event) in
            switch event {
            case .streamAdded(let stream):
                self.handleNewStream(stream)
            case .streamRemoved(let stream):
                self.handleStreamRemoving(stream.id)
            default:
                break
            }
        })