this.socket = socket;
this.config = config;
// Get reader and writer
GuacamoleReader reader = socket.getReader();
GuacamoleWriter writer = socket.getWriter();
// Get protocol / connection ID
String select_arg = config.getConnectionID();
if (select_arg == null)
select_arg = config.getProtocol();
// Send requested protocol or connection ID
writer.writeInstruction(new GuacamoleInstruction("select", select_arg));
// Wait for server args
GuacamoleInstruction args = expect(reader, "args");
// Build args list off provided names and config
List<String> arg_names = args.getArgs();
String[] arg_values = new String[arg_names.size()];
for (int i=0; i<arg_names.size(); i++) {
// Retrieve argument name
String arg_name = arg_names.get(i);
// Get defined value for name
String value = config.getParameter(arg_name);
// If value defined, set that value
if (value != null) arg_values[i] = value;
// Otherwise, leave value blank
else arg_values[i] = "";
}
// Send size
writer.writeInstruction(
new GuacamoleInstruction(
"size",
Integer.toString(info.getOptimalScreenWidth()),
Integer.toString(info.getOptimalScreenHeight()),
Integer.toString(info.getOptimalResolution())
)
);
// Send supported audio formats
writer.writeInstruction(
new GuacamoleInstruction(
"audio",
info.getAudioMimetypes().toArray(new String[0])
));
// Send supported video formats
writer.writeInstruction(
new GuacamoleInstruction(
"video",
info.getVideoMimetypes().toArray(new String[0])
));
// Send args
writer.writeInstruction(new GuacamoleInstruction("connect", arg_values));
// Wait for ready, store ID
GuacamoleInstruction ready = expect(reader, "ready");
List<String> ready_args = ready.getArgs();