这篇主要记录录屏和SFTP的实现。
录屏及视频播放
对于录屏及录屏的播放,因为我们的项目中需要把guacd和java后端分开两台服务器部署,而guacamole的录屏是通过guacd程序录制的。我的要求是在Java后端直接把录好的视频文件通过http前端播放,因此需要把录屏放在Java端的服务器上。
首先稍微修改一下guacamole-common的源码,添加几个可重载的函数,分别是向前端下发ws消息,向guacd上传前端消息以及ws连接关闭的地方。
GuacamoleWebSocketTunnelEndpoint类的onMessage函数中,添加receiveData(message);
try {
// Write received message
writer.write(message.toCharArray());
receiveData(message);
}
catch (GuacamoleConnectionClosedException e) {
logger.debug("Connection to guacd closed.", e);
}
catch (GuacamoleException e) {
logger.debug("WebSocket tunnel write failed.", e);
}
tunnel.releaseWriter();
onClose函数中添加closeConnect函数调用。
public void onClose(Session session, CloseReason closeReason) {
try {
if (tunnel != null)
tunnel.close();
closeConnect();
}
catch (GuacamoleException e) {
logger.debug("Unable to close WebSocket tunnel.", e);
}
}
定义两个可重载的函数
protected void receiveData(String message) {
//logger.info("GuacamoleWebSocketTunnelEndpoint-receiveData");
}
protected void closeConnect() {
//logger.info("GuacamoleWebSocketTunnelEndpoint-receiveData");
}
在Java工程的WebSocketTunnel类中重载函数
receiveData函数用于记录鼠标键盘事件
@Override
protected void receiveData(String message) {
//logger.info("WebSocketTunnel-receiveData : " + message);
// try {
// userConnectLogEntity.getBufferedWriter2().write(message);
// userConnectLogEntity.getBufferedWriter2().newLine();
// userConnectLogEntity.getBufferedWriter2().flush();
// } catch (IOException e) {
// throw new RuntimeException(e);
// }
}
sendInstruction函数,对将要发送给前端的报文进行拦截处理,重点是最后的几行,把报文记录在一个文件中。
Override
protected void sendInstruction(String instruction) throws IOException {
if(instruction.startsWith("0.,36.")) {
uuid = instruction.substring(6, instruction.length()-1);
System.out.println("uuid: "+uuid);
TunnelStream tunnelStream = new TunnelStream();
tunnelStream.setWebSocketTunnel(this);
tunnelStream.setEnd(false);
tunnelStream.setBuffer(null);
streamMap.tunnelStreamMap.put(uuid, tunnelStream);
streamMap.tunnelStreamMap.get(uuid).setOk(false);
}
else if(instruction.contains("application/octet-stream")) {
fileTranfer = true;
GuacamoleParser parser = new GuacamoleParser();
int parsed;
int offset = 0;
int length = instruction.toCharArray().length;
while (true) {
try {
if (!((parsed = parser.append(instruction.toCharArray(), offset, length)) != 0))
break;
}
catch (GuacamoleException e) {
throw new RuntimeException(e);
}
offset += parsed;
length -= parsed;
}
GuacamoleInstruction ins = parser.next();
synchronized (bufferInstructions) {
bufferInstructions.put(ins.getArgs().get(0), ins);
}
}
else if(instruction.contains("17.SFTP: File opened")) {
streamMap.tunnelStreamMap.get(uuid).setOk(true);
}
else if(instruction.contains("8.SFTP: OK")) {
streamMap.tunnelStreamMap.get(uuid).setOk(true);
}
else {
if(fileTranfer) {
if(instruction.startsWith("4.blob")) {
int num1 = instruction.indexOf(",");
int num2 = instruction.indexOf(",", num1+1);
int num3 = instruction.indexOf(".", num1+1);
int id = Integer.parseInt(instru
4049




被折叠的 条评论
为什么被折叠?



