SIP网页电话(WEBRTC)
<h3><strong>简要描述:</strong></h3>
<ul>
<li>需使用HTTPS协议</li>
<li>浏览器允许麦克风</li>
<li>需要引用coolPhone.js , jssip-3.8.1.min.js, 联系商务提供</li>
</ul>
<p><strong>注册示例</strong></p>
<ul>
<li>
<p>HTML</p>
<pre><code> &lt;input type=&quot;text&quot; id=&quot;phoneTel&quot; placeholder=&quot;请输入手机号&quot;&gt;
&lt;button type=&quot;button&quot; id=&quot;phoneBtn&quot; onclick=&quot;cool.action();&quot;&gt;呼叫&lt;/button&gt;
&lt;div style=&quot;display: none;&quot;&gt;
&lt;audio id=&quot;remoteStream&quot;&gt;&lt;/audio&gt;
&lt;/div&gt;</code></pre>
</li>
<li>
<p>JavaScript</p>
<pre><code> &lt;script&gt;
var domain = &quot;webrtc.sipjs.cn&quot;;
var websocket = &quot;wss://&quot; + domain + &quot;:7443&quot;;
var user =&quot;1000&quot;;
var password = &quot;123456&quot;; //分机密码
var remoteStream = document.getElementById(&quot;remoteStream&quot;);
var phoneTel = document.getElementById(&quot;phoneTel&quot;);
var phoneBtn = document.getElementById(&quot;phoneBtn&quot;);
cool.register(websocket, domain, user, password, phoneTel, phoneBtn, remoteStream);
&lt;/script&gt;</code></pre>
</li>
</ul>
<p><strong>参数说明</strong></p>
<table>
<thead>
<tr>
<th>参数名</th>
<th>类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>domain</td>
<td>string</td>
<td>服务器域名,使用时需改为自己拥有的服务器域名</td>
</tr>
<tr>
<td>websocket</td>
<td>string</td>
<td>socket 连接</td>
</tr>
<tr>
<td>user</td>
<td>string</td>
<td>分机号</td>
</tr>
<tr>
<td>password</td>
<td>string</td>
<td>分机密码</td>
</tr>
<tr>
<td>remoteStream</td>
<td>string</td>
<td>audio标签,用于存放提示音</td>
</tr>
<tr>
<td>phoneTel</td>
<td>string</td>
<td>被叫号码</td>
</tr>
<tr>
<td>phoneBtn</td>
<td>string</td>
<td>拨打按钮,根据需要自行修改</td>
</tr>
</tbody>
</table>
<h3><strong>注销:</strong></h3>
<ul>
<li>
<p>JavaScript</p>
<pre><code> cool.terminateSession();
cool.stop();</code></pre>
</li>
</ul>
<h3><strong>检测麦克风</strong></h3>
<ul>
<li>
<p>JavaScript</p>
<p>function getUserMedia(constrains, success, error) {
if (navigator.mediaDevices.getUserMedia) {
//最新标准API
navigator.mediaDevices.getUserMedia(constrains).then(success).catch(error);
} else if (navigator.webkitGetUserMedia) {
//webkit内核浏览器
navigator.webkitGetUserMedia(constrains).then(success).catch(error);
} else if (navigator.mozGetUserMedia) {
//Firefox浏览器
navagator.mozGetUserMedia(constrains).then(success).catch(error);
} else if (navigator.getUserMedia) {
//旧版API
navigator.getUserMedia(constrains).then(success).catch(error);
}
}</p>
<p>function onSuccess(stream) { //耳麦检测,成功
console.log("navigator.getUserMedia success!: ");
stream.getTracks().forEach(function (track) {
track.stop();
});
//可在检测成功时注册软电话
}</p>
<p>function onError(error) { //耳麦检测,失败
console.log("navigator.getUserMedia error: ", error);
}</p>
<p>//调用麦克风检测
getUserMedia({
audio: true
}, onSuccess, onError);</p>
</li>
</ul>