package com.shell.guacamole.endpoint;
import com.shell.guacamole.entity.DeviceLoginInfo;
import com.shell.guacamole.service.IDeviceLoginInfoService;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.net.GuacamoleSocket;
import org.apache.guacamole.net.GuacamoleTunnel;
import org.apache.guacamole.net.InetGuacamoleSocket;
import org.apache.guacamole.net.SimpleGuacamoleTunnel;
import org.apache.guacamole.protocol.ConfiguredGuacamoleSocket;
import org.apache.guacamole.protocol.GuacamoleClientInformation;
import org.apache.guacamole.protocol.GuacamoleConfiguration;
import org.apache.guacamole.websocket.GuacamoleWebSocketTunnelEndpoint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.websocket.EndpointConfig;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;
import java.util.Date;
import java.util.List;
import java.util.Map;
@ServerEndpoint(value = "/tunnel", subprotocols = "guacamole")
@Component
public class WebSocketTunnel extends GuacamoleWebSocketTunnelEndpoint {
private String uuid;
private static IDeviceLoginInfoService deviceLoginInfoService;
private static String guacIp="10.10.10.11";
private static Integer guacPort=4822;
private GuacamoleTunnel guacamoleTunnel;
// websocket中,自动注入及绑定配置项必须用这种方式
@Autowired
public void setDeviceListenerService(IDeviceLoginInfoService deviceListenerService) {
WebSocketTunnel.deviceLoginInfoService = deviceListenerService;
}
//
// @Value("${guacamole.ip}")
// public void setGuacIp(String guacIp) {
// WebSocketTunnel.guacIp = guacIp;
// }
//
// @Value("${guacamole.port}")
// public void setGuacPort(Integer guacPort) {
// WebSocketTunnel.guacPort = guacPort;
// }
@Override
protected GuacamoleTunnel createTunnel(Session session, EndpointConfig endpointConfig) throws GuacamoleException {
//从session中获取传入参数
Map<String, List<String>> map = session.getRequestParameterMap();
String userId = map.get("userId").get(0);
// 根据传入参数从数据库中查找连接信息
// DeviceLoginInfo loginInfo = deviceLoginInfoService.list().get(0);
DeviceLoginInfo loginInfo = new DeviceLoginInfo();
loginInfo.setPort(5901);
loginInfo.setIp("10.10.10.12");
loginInfo.setUser("user1");
loginInfo.setPassword("vnc123");
if(loginInfo != null) {
//String wid = (map.get("width")==null) ? "1413" : map.get("width").get(0);
//String hei = (map.get("height")==null) ? "925" : map.get("height").get(0);
String wid = "2048";
String hei = "1300";
GuacamoleConfiguration configuration = new GuacamoleConfiguration();
configuration.setParameter("hostname", loginInfo.getIp());
configuration.setParameter("port", loginInfo.getPort().toString());
configuration.setParameter("username", loginInfo.getUser());
configuration.setParameter("password", loginInfo.getPassword());
configuration.setProtocol("vnc"); // 远程连接协议
configuration.setParameter("width", wid);
configuration.setParameter("height", hei);
/**开启录屏**/
String fileName =String.valueOf(new Date().getTime());
configuration.setParameter("recording-path", "/var/lib/guacamole/recordings/"+userId);
configuration.setParameter("create-recording-path", "true");
configuration.setParameter("recording-name",fileName );
/**开启录屏**/
GuacamoleClientInformation information = new GuacamoleClientInformation();
information.setOptimalScreenHeight(Integer.parseInt(hei));
information.setOptimalScreenWidth(Integer.parseInt(wid));
GuacamoleSocket socket = new ConfiguredGuacamoleSocket(
new InetGuacamoleSocket(guacIp, guacPort),
configuration, information
);
guacamoleTunnel = new SimpleGuacamoleTunnel(socket);
return guacamoleTunnel;
}
return null;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
guacamole.zip (64个子文件)
guacamole
HELP.md 882B
mvnw.cmd 7KB
recording.guac 7.71MB
guacamole.iml 11KB
pom.xml 4KB
src
test
java
com
shell
guacamole
HttpIpPortValidator.java 1KB
CharIndexFinder.java 1KB
main
resources
mapper
static
playback.js 6KB
play.html 1KB
index.html 4KB
guacamole-common-js
all.js 488KB
modules
Client.js 62KB
IntegerPool.js 2KB
ArrayBufferWriter.js 4KB
InputStream.js 2KB
ArrayBufferReader.js 2KB
VideoPlayer.js 4KB
Event.js 11KB
RawAudioFormat.js 4KB
OutputStream.js 2KB
Tunnel.js 41KB
BlobWriter.js 7KB
Display.js 55KB
OnScreenKeyboard.js 31KB
Parser.js 12KB
AudioPlayer.js 17KB
StringWriter.js 5KB
AudioRecorder.js 19KB
Keyboard.js 47KB
Mouse.js 38KB
UTF8Parser.js 4KB
Status.js 8KB
Object.js 7KB
BlobReader.js 4KB
Namespace.js 1019B
DataURIReader.js 3KB
JSONReader.js 3KB
AudioContextFactory.js 3KB
SessionRecording.js 36KB
InputSink.js 4KB
Version.js 1KB
Layer.js 33KB
StringReader.js 2KB
Touch.js 9KB
Position.js 4KB
all.min.js 71KB
playback.css 2KB
application.yml 523B
java
com
shell
guacamole
mapper
DeviceLoginInfoMapper.java 231B
handler
MessageHandler.java 1KB
servlet
HttpTunnelServlet.java 3KB
controller
GuacamoleController.java 4KB
GuacamoleApplication.java 517B
service
IDeviceLoginInfoService.java 237B
impl
DeviceLoginInfoServiceImpl.java 486B
model
TunnelStream.java 70B
entity
DeviceLoginInfo.java 262B
endpoint
WebSocketTunnel.java 4KB
util
StreamMap.java 196B
config
WebSocketConfig.java 639B
.mvn
wrapper
maven-wrapper.properties 233B
maven-wrapper.jar 61KB
mvnw 11KB
.gitignore 395B
共 64 条
- 1
资源评论
nsa65223
- 粉丝: 142
- 资源: 34
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功