'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服务器上运行。我做了一些改动,实验和大量研究,但结果却相同。当我将它嵌入我们的网站时,按钮不会出现。我无法跟踪有关这些代码的任何错误。有什么问题吗?任何建议都对我有很大的帮助。谢谢。
顺便说一下,这段代码应该可以通过我们办公室的手机拨打电话。点击按钮会将用户引导到网站rtc,这将直接呼叫我们的办公室。
答案 0 :(得分:0)
Chrome不允许在HTTP上使用WebRTC。您必须使用HTTPS或使用Firefox进行测试。