Js SIP 代码在网页上不起作用

Js SIP code does not work on Web Page

本文关键字:不起作用 网页 SIP 代码 Js      更新时间:2023-09-26
    'use strict';
/**
 * Created by tqcenglish on 15-8-12.
 * 若请静态文件使用默认账号,若添加参数则需要服务器动态生成此文件
 */
(function () {
    var createScriptElement = function (src, onload, onerror) {
        var element = document.createElement("script");
        element.type = "text'/javascript";
        element.src = src;
        element.onload = onload;
        element.onerror = onerror;
        return element;
    };

    var createLinkElement = function (src) {
        var element = document.createElement('link');
        element.href = src;
        element.rel = 'Stylesheet';
        element.media_type = 'text/css';
        return element;
    };
    var createUI = function () {
        var clickCallDiv = document.createElement('div');
        clickCallDiv.style.cssText = 'width: 300px;height: 60px;position: fixed;z-index: 999;right: 20px;bottom: 320px;';
        var call_btn = document.createElement("button");
        call_btn.id = "dial_btn_call";
        var session_div = document.createElement("div");
        session_div.id = 'sessions';
        var webcam_div = document.createElement("div");
        webcam_div.style.cssText = 'height:0';
        webcam_div.id = 'webcam';
        var video_remote = document.createElement('video');
        video_remote.id = 'remoteView';
        video_remote.autoplay = 'autoplay';
        video_remote.hidden = 'hidden';
        var video_local = document.createElement('video');
        video_local.autoplay = 'autoplay';
        video_local.hidden = 'hidden';
        video_local.muted = 'muted';
        video_local.id = 'selfView';
        webcam_div.appendChild(video_remote);
        webcam_div.appendChild(video_local);
        clickCallDiv.appendChild(call_btn); //add the text node to the newly created div.
        var contain = document.createElement('div');
        contain.appendChild(session_div);
        contain.appendChild(webcam_div);
        clickCallDiv.appendChild(contain);
        return clickCallDiv;
    };
    var urls = {};
    urls.rtcninja = 'location/rtcninja.js';
    urls.jquery = 'location/jquery.js';
    urls.i18n = "location/jquery.i18n.js";
    urls.messagestore = "location/jquery.i18n.messagestore.js";
    urls.jssip = 'location/jssip.js';
    urls.init = 'location/init.js';
    urls.gui = 'location/gui.js';
    urls.css = 'location/style.css';

    var rtcninja_script = createScriptElement(urls.rtcninja, function () {
        // Must first init the library
        rtcninja();
        // Then check.
        if (!rtcninja.hasWebRTC()) {
            console.log('WebRTC is not supported in your browser :(');
        } else {
            document.body.appendChild(createUI());
        }
    });
    var jquery_script = createScriptElement(urls.jquery, function(){
        document.head.appendChild(i18_script);
        document.head.appendChild(jssip_script);
        document.head.appendChild(gui_script);
        document.head.appendChild(init_script);
    });
    var i18_script = createScriptElement(urls.i18n, function(){
        document.head.appendChild(messagestore_script);
    });
    var messagestore_script = createScriptElement(urls.messagestore);
    var jssip_script = createScriptElement(urls.jssip);
    var init_script = createScriptElement(urls.init);
    var gui_script = createScriptElement(urls.gui);
    var click_call_css = createLinkElement(urls.css);
    document.head.appendChild(jquery_script);
    document.head.appendChild(rtcninja_script);
    document.head.appendChild(click_call_css);
})();

上面的代码在HTTPS Web服务器上完美运行。问题是,我们的网站在HTTP服务器上运行。我做了一些修改,实验和很多研究,但同样的结果发生了。当我将按钮嵌入我们的网站时,它不会出现。我无法跟踪有关这些代码的任何错误。有什么问题吗?任何建议都会对我有很大帮助。谢谢。

顺便说一下,此代码应该能够通过我们办公室的电话拨打电话。 单击该按钮会将用户定向到Web RTC,该RTC将直接致电我们的办公室。

Chrome 不允许在 HTTP 上使用 WebRTC。您必须使用 HTTPS 或使用 Firefox 进行测试。