1
|
define([
|
2
|
'dojo/_base/declare',
|
3
|
'dojo/_base/lang',
|
4
|
'dojo/dom-construct',
|
5
|
'java/applet'
|
6
|
], function(declare, lang, domConstruct, applet){
|
7
|
|
8
|
var Viewer = declare('vnc.Viewer', null, {
|
9
|
|
10
|
started: false,
|
11
|
|
12
|
title: null,
|
13
|
host: null,
|
14
|
port: null,
|
15
|
node: null,
|
16
|
archive: require.toUrl("vnc/resources/vnc.jar"),
|
17
|
|
18
|
constructor: function(args){
|
19
|
lang.mixin(this, args);
|
20
|
|
21
|
this.id = 'vnc-viewer-' + Viewer.id;
|
22
|
Viewer.id = Viewer.id + 1;
|
23
|
if(typeof Viewer.viewers[this.id] !== 'undefined'){
|
24
|
console.log('Viewer already present');
|
25
|
domConstruct.destroy(this.id);
|
26
|
}
|
27
|
Viewer.viewers[this.id] = this;
|
28
|
},
|
29
|
|
30
|
start: function(){
|
31
|
if(this.started){
|
32
|
console.log('error already started');
|
33
|
return;
|
34
|
}
|
35
|
|
36
|
var args = {
|
37
|
port: this.port,
|
38
|
host: this.host,
|
39
|
title: this.title,
|
40
|
id: this.id,
|
41
|
log_level:'info'
|
42
|
};
|
43
|
|
44
|
args.archive = this.archive;
|
45
|
args.cache_archive = this.archive;
|
46
|
args.cache_version = "1";
|
47
|
args.code = 'com.tigervnc.VncApplet';
|
48
|
args.new_window = "Yes";
|
49
|
args.show_controls = 'no';
|
50
|
args.callback = 'vnc.Viewer.javatrigger';
|
51
|
|
52
|
// NOTE:
|
53
|
// Static variables are shared accross applets
|
54
|
// tigervnc uses static variables so it fucks up.
|
55
|
// Disabling the classloader cache
|
56
|
args.classloader_cache = 'false';
|
57
|
applet.inject(this.node, args);
|
58
|
},
|
59
|
|
60
|
stop: function(){
|
61
|
this.onDestroy();
|
62
|
},
|
63
|
|
64
|
onDestroy: function(){
|
65
|
var self = this;
|
66
|
function doIt(){
|
67
|
domConstruct.destroy(this.id);
|
68
|
}
|
69
|
setTimeout(doIt, 0);
|
70
|
},
|
71
|
|
72
|
onStart: function(){
|
73
|
|
74
|
}
|
75
|
});
|
76
|
|
77
|
Viewer.viewers = {};
|
78
|
Viewer.INIT = 'display:init';
|
79
|
Viewer.DESTROY = 'display:destroy';
|
80
|
|
81
|
Viewer.id = 0;
|
82
|
Viewer.javatrigger = function(evtName, id, msg){
|
83
|
console.log('vnc::Viewer::javatrigger', arguments);
|
84
|
var self = this;
|
85
|
var display = self.viewers[id];
|
86
|
|
87
|
function f(){
|
88
|
switch('display:' + evtName){
|
89
|
case self.INIT:
|
90
|
display.onStart();
|
91
|
break;
|
92
|
case self.DESTROY:
|
93
|
display && display.onDestroy();
|
94
|
break;
|
95
|
default:
|
96
|
console.log('WTF? event:' + evtName + " shouldn't happen");
|
97
|
}
|
98
|
}
|
99
|
setTimeout(f, 0);
|
100
|
};
|
101
|
|
102
|
return Viewer;
|
103
|
|
104
|
});
|
105
|
|