websocket 自动识别协议

This commit is contained in:
jiangzeyin 2019-03-26 14:34:41 +08:00
parent d3688d21d8
commit 55a6c385df
3 changed files with 8 additions and 3 deletions

View File

@ -43,4 +43,9 @@
// 创建完后切换
element.tabChange('mainTabs', lay_id);
}
function getSocketHost() {
var pro = location.protocol === 'https:' ? 'wss://' : 'ws://';
return pro + window.location.host;
}
</script>

View File

@ -90,7 +90,7 @@
function loadSuccess() {
const showLogDom = $('.console .terminal');
if ('WebSocket' in window) {
const ws = new WebSocket("ws://" + window.location.host + "/console/$userInfo/$!projectInfo.id");
const ws = new WebSocket(getSocketHost() + "/console/$userInfo/$!projectInfo.id");
ws.onopen = function () {
showLogDom.append('WebSocket连接成功<br/>');
setMsg('status');

View File

@ -132,11 +132,11 @@
function linkSocket(status) {
if (!ws) {
ws = new WebSocket("ws://" + window.location.host + "/console/$userInfo/system");
ws = new WebSocket(getSocketHost() + "/console/$userInfo/system");
}
if (status) {
if (ws.readyState != 1 && ws.readyState != 0) {
ws = new WebSocket("ws://" + window.location.host + "/console/$userInfo/system");
ws = new WebSocket(getSocketHost() + "/console/$userInfo/system");
}
ws.onopen = function () {
ws.send('{"op": "top", "projectInfo":{}}');