Updated on 2023-10-12 GMT+08:00

Registering an Account

Application Scenario

Register an account using an agent's phone.

Prerequisites

The OpenEyeCall parameters have been initialized, and the SIP server information is correct.

Process Description

Invoke the register interface of OpenEyeCall to answer a call.

  • When the registration interface is invoked, the returned result needs to be processed, and the onRegStatusUpdate event needs to be listened to.
  • Registration is an asynchronous process. The returned result 0 does not necessarily indicate a successful registration. The registration is successful only when the value of register_state returned by onRegStatusUpdate is 3.
/**
* Register
 */
function register() { 
    var phoneNumber = document.getElementById("phoneNumber").value;
    var password = document.getElementById("password").value;
    userPhoneNumber = phoneNumber + "@" + GlobalSipIp;//OpenEyeConfig.domain;
	console.info("register info="+userPhoneNumber);

	var sipMode=1;
	if(EnablePoolMode){
		sipMode=1;
	}
    this.global_openEye_SDK.openEyeCall.register(userPhoneNumber, phoneNumber, password, sipMode, {
        onRegStatusUpdate: onRegStatusUpdate,
        onForceUnReg: onForceUnRegInfo,
        response: registerResponse
    });
} 
/**
* Registration result
 * @param {*} data 
 */
function registerResponse(data) { 
   if (data.result == 0) {
        console.info("Register Operation Success");
	getMediaDevices();
    } else {
        console.error("Register Operation Failed");
        console.error(data);
    }

} 

/**
* Registration result reporting
 * @param {*} data 
 */
function onRegStatusUpdate(data) { 
    var userNumber = data.param.user_number;
    var state = ["unregister", "registering", "deregistering", "registered", "deregistered"];
    var reason = data.param.reason_code; //complete reason code refer to: http://blog.csdn.net/kafeiwuzhuren/article/details/7242791    
    if (reason == 403) {
        console.log("403:forbidden");
    }
    if (reason == 408) {
        console.log("408:request overtime");
    }
    var currentState = state[data.param.register_state];
    var obj = { userNum: userNumber, stateInfo: currentState, reasonInfo: reason }
    console.log("onRegStatusUpdate");
    console.log(data);
    document.getElementById("phoneStatus").innerText = obj.stateInfo;
    if (data.param.register_state == 3) {
        document.getElementById("voiceControlDiv").style.visibility = "visible";
    }
	if(data.notify==1004){
		document.getElementById("phoneStatus").innerText = "Login successful";
		document.getElementById("voiceControlDiv").style.visibility = "visible";
	}

} 

function onForceUnRegInfo(data) { 
    document.getElementById("phoneStatus").innerText = "DeRegister";
    document.getElementById("voiceControlDiv").style.visibility = "hidden";
    userPhoneNumber = "";
    tupCurrentCallId = "";
    console.log("onForceUnRegInfo");
    console.log(data);

}