import JsSIP from "jssip" 
let userAgent
export function  initSip(selectExten) {
    const ws_uri_ = import.meta.env.VITE_APP_SIP_URL 
    const sip_uri_ = "sip:" + selectExten + "@"+import.meta.env.VITE_APP_SIP_IP
    const sip_password_ = import.meta.env.VITE_APP_SIP_PASSWORD
    const contact_uri = import.meta.env.VITE_APP_SIP_CONTACT_URL
    const socket = new JsSIP.WebSocketInterface(ws_uri_);
    const configuration = {
		sockets: [socket],
		outbound_proxy_set: ws_uri_,
		uri: sip_uri_, //与用户代理关联的SIP URI（字符串）。这是您的提供商提供给您的SIP地址
		password: sip_password_, //SIP身份验证密码
		contact_uri: 'sip:' + selectExten + contact_uri,
		register: true, //指示启动时JsSIP用户代理是否应自动注册
		session_timers: false, //启用会话计时器（根据RFC 4028）
	};
    console.log(configuration)
    userAgent = new JsSIP.UA(configuration)
    JsSIP.debug.disable('JsSIP:*');
    userAgent.on('registered', function(data) {
		console.info("registered: ", data.response.status_code, ",", data.response.reason_phrase);
	});
    userAgent.on('registrationFailed', function(data) {
		console.log("registrationFailed, ", data); 
	});
	userAgent.start();
}