简体   繁体   中英

Js SIP code does not work on Web Page

    '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);
})();

The above code is perfectly working on a HTTPS web server. The problem is, our website is running on HTTP server. I have done some few alterations, experimentation and a lot of research but the same result occurs. Button does not appear when I am embedding it on our website. I cannot track any error regarding these codes. Anything wrong with it? Any suggestion would be a great help for me. Thanks.

By the way, this code should be able to call through our phones on our office. clicking the button would direct user to the web rtc which would directly call our office.

Chrome doesn't allow WebRTC on HTTP. You must use HTTPS or test with Firefox.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM