Commit 910eda56 authored by Fernando Verdugo's avatar Fernando Verdugo
Browse files

wip(websocket): remove files from original project

Issue #1036
parent de05aefe
The MIT License (MIT)
Copyright (c) 2016 eyeOS S.L.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This diff is collapsed.
/*
eyeOS Spice Web Client
Copyright (c) 2015 eyeOS S.L.
Contact Jose Carlos Norte (jose@eyeos.com) for more information about this software.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Affero General Public License version 3 as published by the
Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
details.
You should have received a copy of the GNU Affero General Public License
version 3 along with this program in the file "LICENSE". If not, see
<http://www.gnu.org/licenses/agpl-3.0.txt>.
See www.eyeos.org for more details. All requests should be sent to licensing@eyeos.org
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License version 3.
In accordance with Section 7(b) of the GNU Affero General Public License version 3,
these Appropriate Legal Notices must retain the display of the "Powered by
eyeos" logo and retain the original copyright notice. If the display of the
logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
must display the words "Powered by eyeos" and retain the original copyright notice.
*/
wdi.Agent = $.spcExtend(wdi.EventObject.prototype, {
clientTokens:null,
serverTokens: 10,
app: null,
clipboardContent: null,
clipboardGrabbed: false,
clipboardRequestReceived: false,
clipboardPending: false, // to keep clipboard data until spice sends us its request (clipboardRequestReceived)
clipboardEnabled: true,
windows: null,
init: function(c) {
this.superInit();
this.app = c.app;
},
sendInitMessage: function() {
var packet = new wdi.SpiceMessage({
messageType: wdi.SpiceVars.SPICE_MSGC_MAIN_AGENT_START,
channel: wdi.SpiceVars.SPICE_CHANNEL_MAIN,
args: new wdi.SpiceMsgMainAgentTokens({
num_tokens: this.serverTokens
})
});
this.app.spiceConnection.send(packet);
var mycaps = (1 << wdi.AgentCaps.VD_AGENT_CAP_MONITORS_CONFIG);
if (this.clipboardEnabled) {
mycaps = mycaps | (1 << wdi.AgentCaps.VD_AGENT_CAP_CLIPBOARD_BY_DEMAND);
}
packet = new wdi.SpiceMessage({
messageType: wdi.SpiceVars.SPICE_MSGC_MAIN_AGENT_DATA,
channel: wdi.SpiceVars.SPICE_CHANNEL_MAIN,
args: new wdi.VDAgentMessage({
protocol: 1, //agent protocol version, should be unhardcoded
type: wdi.AgentMessageTypes.VD_AGENT_ANNOUNCE_CAPABILITIES,
opaque: 0,
data: new wdi.VDAgentAnnounceCapabilities({
request: 0,
caps: mycaps
})
})
});
this.sendAgentPacket(packet);
// //tokens allocation
// packet = new wdi.SpiceMessage({
// messageType: wdi.SpiceVars.SPICE_MSGC_MAIN_AGENT_TOKEN,
// channel: wdi.SpiceVars.SPICE_CHANNEL_MAIN,
// args: new wdi.SpiceMsgMainAgentTokens({
// num_tokens: 4294967295 // FF FF FF FF
// })
// });
// app.spiceConnection.send(packet);
},
setResolution: function(width, height) {
//TODO move this to a setting
if(width < 800) {
width = 800;
}
if(height < 600) {
height = 600;
}
//adapt resolution, TODO: this needs to be refractored
var packet = new wdi.SpiceMessage({
messageType: wdi.SpiceVars.SPICE_MSGC_MAIN_AGENT_DATA,
channel: wdi.SpiceVars.SPICE_CHANNEL_MAIN,
args: new wdi.VDAgentMessage({
protocol: 1, //agent protocol version, should be unhardcoded
type: wdi.AgentMessageTypes.VD_AGENT_MONITORS_CONFIG,
opaque: 0,
data: new wdi.VDAgentMonitorsConfig({
num_of_monitors: 1,
flags: 0,
data: new wdi.VDAgentMonConfig({
width: width,
height: height,
depth: 32,
x: 0,
y: 0
})
})
})
});
this.sendAgentPacket(packet);
},
setClientTokens: function(tokens) {
this.clientTokens = tokens;
},
sendAgentPacket: function(packet) {
this.clientTokens--;
this.app.spiceConnection.send(packet);
},
onAgentData: function(packet) {
this.serverTokens--; //we have just received a server package, we decrement the tokens
if (this.serverTokens == 0) { // we send 10 more tokens to server
packet = new wdi.SpiceMessage({
messageType: wdi.SpiceVars.SPICE_MSGC_MAIN_AGENT_TOKEN,
channel: wdi.SpiceVars.SPICE_CHANNEL_MAIN,
args: new wdi.SpiceMsgMainAgentTokens({
num_tokens: 10
})
});
this.app.spiceConnection.send(packet);
this.serverTokens = 10;
}
if(packet.type == wdi.AgentMessageTypes.VD_AGENT_ANNOUNCE_CAPABILITIES) {
//??
} else if(packet.type == wdi.AgentMessageTypes.VD_AGENT_CLIPBOARD_GRAB) {
if(packet.clipboardType == wdi.ClipBoardTypes.VD_AGENT_CLIPBOARD_UTF8_TEXT) {
var packet = new wdi.SpiceMessage({
messageType: wdi.SpiceVars.SPICE_MSGC_MAIN_AGENT_DATA,
channel: wdi.SpiceVars.SPICE_CHANNEL_MAIN,
args: new wdi.VDAgentMessage({
protocol: 1, //agent protocol version, should be unhardcoded
type: wdi.AgentMessageTypes.VD_AGENT_CLIPBOARD_REQUEST,
opaque: 0,
data: new wdi.VDAgentClipboardRequest({
type: wdi.ClipBoardTypes.VD_AGENT_CLIPBOARD_UTF8_TEXT
})
})
});
this.sendAgentPacket(packet);
}
} else if(packet.type == wdi.AgentMessageTypes.VD_AGENT_CLIPBOARD) {
this.fire('clipBoardData', packet.clipboardData);
} else if (packet.type == wdi.AgentMessageTypes.VD_AGENT_CLIPBOARD_REQUEST) {
this.clipboardRequestReceived = true;
if (this.clipboardPending) {
this.clipboardPending = false;
this.sendPaste();
}
} else if (packet.type == wdi.AgentMessageTypes.VD_AGENT_CLIPBOARD_RELEASE) {
//debugger;// we've never seen this packet... if we receive it sometime, please warn somebody!!
this.clipboardGrabbed = false;
this.clipboardRequestReceived = false;
} else if (packet.type == wdi.AgentMessageTypes.VD_AGENT_REPLY) {
} else {
console.log('agent ?',packet.type);
}
},
setClipboard: function(text) {
if (text != this.clipboardContent) {
this.clipboardContent = text;
this.sendGrab();
this.sendPaste();
}
this.app.sendShortcut(wdi.keyShortcutsHandled.CTRLV);
},
sendGrab: function() {
if (!this.clipboardGrabbed) {
var packet = new wdi.SpiceMessage({
messageType: wdi.SpiceVars.SPICE_MSGC_MAIN_AGENT_DATA,
channel: wdi.SpiceVars.SPICE_CHANNEL_MAIN,
args: new wdi.VDAgentMessage({
protocol: 1, //agent protocol version, should be unhardcoded
type: wdi.AgentMessageTypes.VD_AGENT_CLIPBOARD_GRAB,
opaque: 0,
data: new wdi.VDAgentClipboardGrab({
types: [wdi.ClipBoardTypes.VD_AGENT_CLIPBOARD_UTF8_TEXT]
})
})
});
this.sendAgentPacket(packet);
}
},
/**
* Sends the text received from browser to spice
*
* @param clipboardContent
*/
sendPaste: function() {
if (this.clipboardRequestReceived) {
var packet = new wdi.SpiceMessage({
messageType: wdi.SpiceVars.SPICE_MSGC_MAIN_AGENT_DATA,
channel: wdi.SpiceVars.SPICE_CHANNEL_MAIN,
args: new wdi.VDAgentMessage({
protocol: 1, //agent protocol version, should be unhardcoded
type: wdi.AgentMessageTypes.VD_AGENT_CLIPBOARD,
opaque: 0,
data: new wdi.VDAgentClipboard({
type: wdi.ClipBoardTypes.VD_AGENT_CLIPBOARD_UTF8_TEXT,
data: this.clipboardContent
})
})
});
this.clipboardRequestReceived = false;
this.sendAgentPacket(packet);
} else {
// we still haven't received the request event from server, we keep the clipboard data until then
this.clipboardPending = true;
}
},
disableClipboard: function () {
this.clipboardEnabled = false;
}
});
/*
eyeOS Spice Web Client
Copyright (c) 2015 eyeOS S.L.
Contact Jose Carlos Norte (jose@eyeos.com) for more information about this software.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Affero General Public License version 3 as published by the
Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
details.
You should have received a copy of the GNU Affero General Public License
version 3 along with this program in the file "LICENSE". If not, see
<http://www.gnu.org/licenses/agpl-3.0.txt>.
See www.eyeos.org for more details. All requests should be sent to licensing@eyeos.org
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License version 3.
In accordance with Section 7(b) of the GNU Affero General Public License version 3,
these Appropriate Legal Notices must retain the display of the "Powered by
eyeos" logo and retain the original copyright notice. If the display of the
logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
must display the words "Powered by eyeos" and retain the original copyright notice.
*/
Application = $.spcExtend(wdi.DomainObject, {
spiceConnection: null,
clientGui: null,
agent: null,
externalCallback: null,
keyboardEnabled: true,
packetProcess: null,
inputProcess: null,
multimediaTime: null,
lastMultimediaTime: null,
busConnection: null,
busProcess: null,
timeLapseDetector: null,
init: function (c) {
wdi.GlobalPool.init();
this.spiceConnection = c.spiceConnection || new wdi.SpiceConnection();
this.clientGui = c.clientGui || new wdi.ClientGui();
this.agent = c.agent || new wdi.Agent({
app: this
});
this.inputProcess = c.inputProcess || new wdi.InputProcess({
clientGui: this.clientGui,
spiceConnection: this.spiceConnection
});
this.packetProcess = c.packetProcess;
this.busConnection = c.busConnection || new wdi.BusConnection();
this.busProcess = c.busProcess || new wdi.BusProcess({
clientGui: this.clientGui,
busConnection: this.busConnection
});
this.timeLapseDetector = c.timeLapseDetector || new wdi.TimeLapseDetector();
this.setup();
},
run: function (c) {
if(c.hasOwnProperty('seamlessDesktopIntegration')) {
wdi.SeamlessIntegration = c['seamlessDesktopIntegration'];
}
if (!this.packetProcess) {
var displayProcess = false;
if (c.useWorkers === false) {
displayProcess = new wdi.DisplayProcess({
clientGui: this.clientGui
});
}
this.packetProcess = new wdi.PacketProcess({
app: this,
clientGui: this.clientGui,
agent: this.agent,
spiceConnection: this.spiceConnection,
inputsProcess: this.inputProcess,
displayProcess: displayProcess
})
}
if (window.vdiLoadTest) {
this.spiceConnection.addListener('message', this.onMessage, this);
} else {
this.spiceConnection.addListener('message', this.packetProcess.process, this.packetProcess);
}
this.busConnection.connect(c);
this.timeLapseDetector.startTimer();
if (c['canvasMargin']) {
this.clientGui.setCanvasMargin(c['canvasMargin']);
}
if (c['disableClipboard']) {
this.agent.disableClipboard();
this.clientGui.disableClipboard();
this.enableCtrlV();
}
if(c['layer']) {
this.clientGui.setLayer(c['layer']);
}
if (this.clientGui.checkFeatures()) {
if (wdi.SeamlessIntegration) {
this.disableKeyboard();//keyboard should start disabled is integrated
}
wdi.Keymap.loadKeyMap(c['layout']);
this.setExternalCallback(c['callback'], c['context']);
try {
this.connect({
host: c['host'],
port: c['port'],
protocol: c['protocol'],
vmHost: c['vmHost'],
vmPort: c['vmPort'],
vmInfoToken: c['vmInfoToken'],
busHost: c['busHost'],
token: c['token'],
connectionControl: c['connectionControl'],
heartbeatToken: c['heartbeatToken'],
heartbeatTimeout: c['heartbeatTimeout']
});
} catch (e) {
this.executeExternalCallback('error', 1);
}
this.clientGui.setClientOffset(c['clientOffset']['x'], c['clientOffset']['y']);
}
if (c.hasOwnProperty('externalClipboardHandling')) {
this.externalClipoardHandling = c['externalClipboardHandling'];
}
},
end: function () {
//TODO: end?
},
setup: function () {
this.spiceConnection.addListener('mouseMode', this.onMouseMode, this);
this.spiceConnection.addListener('initAgent', this.onInitAgent, this);
this.spiceConnection.addListener('error', this.onDisconnect, this);
this.spiceConnection.addListener('channelConnected', this.onChannelConnected, this);
this.clientGui.addListener('input', this.onClientInput, this);
this.clientGui.addListener('resolution', this.onResolution, this);
this.clientGui.addListener('paste', this.onPaste, this);
this.clientGui.addListener('startAudio', this.onStartAudio, this);
this.busProcess.addListener('windowCreated', this.onWindowCreated, this);
this.busProcess.addListener('windowClosed', this.onWindowClosed, this);
this.busProcess.addListener('windowMoved', this.onWindowMoved, this);
this.busProcess.addListener('windowResized', this.onWindowResized, this);
this.busProcess.addListener('windowFocused', this.onWindowFocused, this);
this.busProcess.addListener('windowMinimized', this.onWindowMinimized, this);
this.busProcess.addListener('windowRestored', this.onWindowRestored, this);
this.busProcess.addListener('windowMaximized', this.onWindowMaximized, this);
this.busProcess.addListener('busConnected', this.onBusConnected, this);
this.busProcess.addListener('menuResponse', this.onMenuResponse, this);
this.busProcess.addListener('networkDriveResponse', this.onNetworkDriveResponse, this);
this.busProcess.addListener('wrongPathError', this.onWrongPathError, this);
this.busProcess.addListener('applicationLaunchedSuccessfully', this.onApplicationLaunchedSuccessfully, this);
this.agent.addListener('clipBoardData', this.onClipBoardData, this);
this.busConnection.addListener('busMessage', this.onBusMessage, this);
this.busConnection.addListener('error', this.onDisconnect, this);
this.timeLapseDetector.addListener('timeLapseDetected', this.onTimeLapseDetected, this);
},
onChannelConnected: function(params) {
var channel = params;
if (channel === wdi.SpiceVars.SPICE_CHANNEL_INPUTS) {
this.clientGui.releaseAllKeys();
}
},
onNetworkDriveResponse: function(params) {
this.executeExternalCallback('networkDriveResponse', params);
},
onDisconnect: function (params) {
var error = params;
this.executeExternalCallback('error', error);
},
onResolution: function (params) {
this.executeExternalCallback('resolution', params);
},
onClipBoardData: function (params) {
if (this.externalClipoardHandling) {
this.executeExternalCallback('clipboardEvent', params);
} else {
this.clientGui.setClipBoardData(params);
}
},
onWindowMinimized: function (params) {
var window = params;
var params = this.clientGui.resizeSubCanvas(window);
this.executeExternalCallback('windowMinimized', params);
},
onWindowFocused: function (params) {
this.executeExternalCallback('windowFocused', params);
},
onWindowRestored: function (params) {
var window = params;
var params = this.clientGui.resizeSubCanvas(window);
this.executeExternalCallback('windowRestored', params);
},
onWindowMaximized: function (params) {
var window = params;
var params = this.clientGui.resizeSubCanvas(window);
this.executeExternalCallback('windowMaximized', params);
},
onWindowResized: function (params) {
var window = params;
var params = this.clientGui.resizeSubCanvas(window);
this.executeExternalCallback('windowResized', params);
},
onWindowMoved: function (params) {
var window = params;
var params = this.clientGui.moveSubCanvas(window);
this.executeExternalCallback('windowMoved', params);
},
onWindowClosed: function (params) {
var window = params;
var params = this.clientGui.deleteSubCanvas(window);
this.executeExternalCallback('windowClosed', params);
},
onWindowCreated: function (params) {
var window = params;
var params = this.clientGui.createNewSubCanvas(window);
this.executeExternalCallback('windowCreated', params);
},
onMenuResponse: function(params) {
var menuData = params;
this.executeExternalCallback('menuResponse', menuData);
},
//Events
onClientInput: function (params) {
var data = params;
var type = data[0];
this.inputProcess.send(data, type);
},
onMessage: function (params) {
var message = params;
this.packetProcess.process(message);
var self = this;
window.checkResultsTimer && clearTimeout(window.checkResultsTimer);
window.checkResultsTimer = window.setTimeout(function () {
self.executeExternalCallback('checkResults');
window.vdiLoadTest = false;
}, 5000);
},
onBusConnected: function(params) {
if (wdi.SeamlessIntegration) {
this.busProcess.requestWindowList(); //request windows list
}
},
onBusMessage: function (params) {
var message = params;
this.busProcess.process(message);
},
onInitAgent: function (params) {
this.agent.setClientTokens(params);
this.agent.sendInitMessage(this);
this.executeExternalCallback('ready', params);
// this.clientGui.releaseAllKeys();
},
onMouseMode: function (params) {
this.clientGui.setMouseMode(params);
},
onPaste: function (params) {
this.agent.setClipboard(params);
},
onStartAudio: function () {
this.packetProcess.processors[wdi.SpiceVars.SPICE_CHANNEL_PLAYBACK].startAudio();
},
onTimeLapseDetected: function (params) {
var elapsedMillis = params;
this.executeExternalCallback('timeLapseDetected', elapsedMillis);
},
connect: function (connectionInfo) {
try {
this.spiceConnection.connect(connectionInfo);
} catch (e) {
this.clientGui.showError(e.message);
}
},
setExternalCallback: function (fn, context) {
this.externalCallback = [fn, context];
},
executeExternalCallback: function (action, params) {
this.externalCallback[0].call(this.externalCallback[1], action, params);
},
sendCommand: function (action, params) {
switch (action) {
case "close":
this.busProcess.closeWindow(