import {connect} from 'diarupt';
import {createSession} from './session';

(async() => {
    const session_id = await createSession();
    const ai_feed = document.getElementById('ai-video');
    
    // get the user's audio stream
    const stream = await navigator.mediaDevices.getUserMedia({
        audio: {
            echoCancellation: true,
            noiseSuppression: true,
            autoGainControl: false,
        },
    });

    const options = {
        stream,
        player: ai_feed,
    }

    const next = (event, data) => {
        // handle events
        console.log(event, data);
    }

    // starts the interaction
    await connect(
        session_id,
        options,
        next
    )
})();

The connect function is used to setup a new webrtc connection to Diarupt Engine. It is required to initiate an AI interaction on the client.

Parameters

session_id
string
required

The session_id is a unique identifier for the current session. It is used to identify the interactions session on the server. It can be retrieved when you create a new session.

options
object
required

Connection options

next
function
required

The next callback is called when an event occurs on the connection. It is used to handle the interaction events. See Interaction Events for more details

Returns

void
Promise<void>

The connect function returns Promise of type void