im_sunlogin_wev8.js
8.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
var msgEle, loadEle, textEle, wrapper;
var isHideMsg = false;
var isMenuInited = false;
var MENU_TPLS = {
"windows": [
'<a href="javascript:void(0);"><i class="icon icon-drop" style="margin: 13px 0 0 0;"></i><\/a><\/div>',
'<div class="toolbar" id="toolbar">',
'<ul>',
'<li>',
'<a href="javascript:void(0);" data-name="switch-screen"><i class="icon icon-screen"></i>切换屏幕<\/a><div class="menu">',
'<ul id="screen-list">',
'<\/ul><\/div>',
'<\/li>',
'<li>',
'<a href="javascript:void(0);" data-name="switch-session"><i class="icon icon-session"></i>切换会话<\/a><div class="menu">',
'<ul id="session-list">',
'<\/ul><\/div>',
'<\/li>',
'<li><a href="javascript:void(0);" data-name="hotkey"><i class="icon icon-hotkey"></i>快捷键<\/a><div class="menu">',
'<ul>',
'<li><a href="javascript:void(0)" data-action="hotKey" data-param="[17, 18, 46]">Ctrl+Alt+Delete<\/a><\/li>',
'<li><a href="javascript:void(0)" data-action="hotKey" data-param="[91, 76]">锁定桌面<\/a><\/li>',
'<li><a href="javascript:void(0)" data-action="sendSysMessage" data-param="3">注销<\/a><\/li>',
'<li><a href="javascript:void(0)" data-action="sendSysMessage" data-param="2">重新启动<\/a><\/li>',
'<li><a href="javascript:void(0)" data-action="sendSysMessage" data-param="1">关机<\/a><\/li>',
'<\/ul>',
'<ul>',
'<li><a href="javascript:void(0)" data-action="hotKey" data-param="[91, 69]">资源管理器<\/a><\/li>',
'<li><a href="javascript:void(0)" data-action="hotKey" data-param="[17, 16, 27]">任务管理器<\/a><\/li>',
'<li><a href="javascript:void(0)" data-action="sendSysMessage" data-param="4">CMD<\/a><\/li>',
'<\/ul>',
'<\/div>',
'<\/li>',
'<\/ul>'
].join(''),
"android": [
'<a href="javascript:void(0);"><i class="icon icon-drop" style="margin: 13px 0 0 0;"></i><\/a><\/div>',
'<div class="toolbar" id="toolbar">',
'<ul>',
'<li>',
'<a href="javascript:void(0);" data-name="switch-screen"><i class="icon icon-screen"></i>屏幕<\/a><div class="menu">',
'<ul id="screen-list">',
'<\/ul><\/div>',
'<\/li>',
'<li>',
'<a href="javascript:void(0);" data-name="switch-session"><i class="icon icon-session"></i>切换会话<\/a><div class="menu">',
'<ul id="session-list">',
'<\/ul><\/div>',
'<\/li>',
'<li><a href="javascript:void(0);" data-name="hotkey"><i class="icon icon-hotkey"></i>快捷键<\/a><div class="menu">',
'<ul>',
'<li><a href="javascript:void(0)" data-action="sendKeys" data-param="[17, 18, 46]">Ctrl+Alt+Delete<\/a><\/li>',
'<li><a href="javascript:void(0)" data-action="sendKeys" data-param="[91, 76]">锁定桌面<\/a><\/li>',
'<li><a href="javascript:void(0)" data-action="sendSysMessage" data-param="3">注销<\/a><\/li>',
'<li><a href="javascript:void(0)" data-action="sendSysMessage" data-param="2">重新启动<\/a><\/li>',
'<li><a href="javascript:void(0)" data-action="sendSysMessage" data-param="1">关机<\/a><\/li>',
'<\/ul>',
'<ul>',
'<li><a href="javascript:void(0)" data-action="sendKeys" data-param="[91, 69]">资源管理器<\/a><\/li>',
'<li><a href="javascript:void(0)" data-action="sendKeys" data-param="[17, 16, 27]">任务管理器<\/a><\/li>',
'<li><a href="javascript:void(0)" data-action="sendSysMessage" data-param="4">CMD<\/a><\/li>',
'<\/ul>',
'<\/div>',
'<\/li>',
'<\/ul>'
].join('')
};
window.addEventListener('load', function() {
msgEle = document.getElementById('msg');
loadEle = document.getElementById('loading-animate');
textEle = document.getElementById('msg-text');
wrapper = document.getElementById('wrapper');
});
// 适应视图位置
function adjustWrapperPosition() {
wrapper.style.position = 'absolute';
var posX = Math.max(0, ~~ ((document.body.offsetWidth - wrapper.offsetWidth) / 2));
var posY = Math.max(0, ~~ ((document.body.offsetHeight - wrapper.offsetHeight) / 2));
wrapper.style.left = posX + 'px';
wrapper.style.top = posY + 'px';
//wrapper.style.marginLeft = (-1 * wrapper.offsetWidth / 2) + 'px';
//wrapper.style.marginTop = (-1 * wrapper.offsetHeight / 2) + 'px';
}
function updateMessage(text, isLoading) {
if (typeof(isLoading) == 'undefined') {
isLoading = true;
}
msgEle.style.display = '';
isHideMsg = false;
textEle.innerHTML = text;
if (isLoading) {
loadEle.style.display = 'inline-block';
} else {
loadEle.style.display = 'none';
}
}
function hideMessage() {
if (isHideMsg) {
return ;
}
msgEle.style.display = 'none';
isHideMsg = true;
}
function initMenu(platform) {
if (isMenuInited) {
return ;
}
isMenuInited = true;
var drop = document.createElement('div');
drop.id = 'drop';
drop.className = 'drop';
drop.innerHTML = MENU_TPLS[platform];
document.body.insertBefore(drop, document.body.childNodes[0]);
drop.addEventListener('click', function() {
drop.style.display = 'none';
document.getElementById('toolbar').style.display = 'block';
});
}
function destroyMenu() {
document.body.removeChild(document.getElementById('drop'));
}
addEventListener('load', function () {
var validParameter = true;
if (validParameter) {
// START 向日葵远程桌面
var client = new SunloginControl.Client({
// 客户端
// SDK
host: host, // FROM SDK: PHSRC://11840.slp2p-live01.oray.net:4118/;PHSRC_HTTPS://11840.slp2p-live01.oray.net:443/;UsingMultiChannel://; 只要主机名
embed: true, // SDK 传true
ssl: false, // slp2p 线上没有证书,如果是独立服务器且SSL配置齐全,可打开
cid: cid, // FROM SDK: CID
port: 80,
debug: false // 控制台日志输出,生产环境请关闭debug
});
updateMessage('开始连接');
// 初始化桌面视图
var wrapper = document.getElementById('wrapper');
var view = new SunloginControl.DesktopView(wrapper);
client
.connect() // 客户端连接开始
.then(function() {
// disconnect 应该放在连接成功之后监听,连接失败直接通过catch捕获
// 否则连接过程中可能会有若干次disconnect事件
client.on('disconnect', function () {
wrapper.style.display = 'none';
updateMessage('连接断开', false);
console.log("连接断开");
setTimeout(function () {
window.close();
},10*1000);
view = null;
delete view;
});
// 连接桌面插件
const desktop = new SunloginControl.Plugin.Desktop({ quality: 10 });
client.connectPlugin(desktop);
updateMessage('连接成功,等待桌面图像');
// imageinfo 桌面图像信息
desktop.on('imageinfo', function(info) {
view.setImageInfo(info);
});
desktop.on('screen', function(count) {
console.log('屏幕数量:' + count);
});
desktop.on('session', function(sessions) {
console.log('系统会话:', sessions);
});
desktop.on('stream', function(stream, info) {
view.decode(stream, info);
hideMessage();
adjustWrapperPosition();
});
// 传输鼠标(触摸)& 键盘(Win)事件,不传输任何主控端事件,即为观看
desktop.transportMouseEvent(wrapper);
desktop.transportKeyBoardEvent(wrapper);
})
.catch(function(e){
console.log("Error occured: ", e);
updateMessage("连接失败: " + e, false);
});
// 页面unload关闭客户端连接
window.onunload = function () {
client.disconnect();
}
}
});