Support & information center

Wait for an agent to register

Sometimes, you want the agents in your test case to log in to the system and register before other agents try and call them or interact with them. To that end, you can use .rtcSetSessionValue() and .rtcWaitForSessionValue() commands defined in testRTC.

The code sample below gets the first agent in each session to send out a message that it is ready to all other agents in the same session so they can start interacting with it.

var agentType = Number(process.env.RTC_IN_SESSION_ID); 

if (agentType === 1) 
{
    // The callee
    client
        .rtcInfo("The callee")        
         
         // Preparations
         
         // Signal the caller that we are ready to receive the call
        .rtcSetSessionValue("sessionReady", "Ready")
        
        // Wait for the call

        // Answer
        .click('#answer');
}
else
{
    // The caller
    client
        .rtcInfo("The caller")
        
        .rtcProgress("Calling")

        // Wait until the callee is ready to receive the call
        .rtcWaitForSessionValue('sessionReady', function (ignoreMe) {}, 20000)

        .rtcInfo("The callee is ready. Initiating a Call...")

        // Initiate the call
        .click('#call');
}

// Shared code for both users after the call was started
client
    .rtcProgress("In a call")
    .pause(15000)
Code language: PHP (php)

Was this article helpful?

Related Articles