Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify tty default working dir to project dir #10

Merged
merged 1 commit into from
Sep 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/java/net/coding/ide/config/WebSocketConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
@Value("#{'${ALLOWED_ORIGINS}'.split(',')}")
private String[] allowedOrigins;

@Value("${SPACE_HOME}")
private String spaceHome;

@Autowired
private WebSocketSessionStore webSocketSessionStore;

Expand Down Expand Up @@ -82,6 +85,7 @@ public ServletRegistrationBean servletRegistrationBean() {
bean.addInitParameter("socketio-heartbeat", "15000");
bean.addInitParameter("socketio-suspendTime", "30000");
bean.addInitParameter("org.atmosphere.cpr.sessionSupport", "true");
bean.addInitParameter("SPACE_HOME", spaceHome);
bean.setLoadOnStartup(100);
bean.setAsyncSupported(true);

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/coding/ide/model/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ public static class Arg {
private String input;

private String cwd;

private String spaceKey;
}
}
21 changes: 17 additions & 4 deletions src/main/java/net/coding/ide/tty/SocketIOHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import static java.lang.String.format;

/**
* Simple SocketIOAtmosphereHandler that implements the logic to build a
* SocketIO Chat application.
Expand All @@ -44,7 +47,6 @@ public class SocketIOHandler extends SocketIOAtmosphereHandler {

public void onConnect(AtmosphereResource r, SocketIOSessionOutbound outbound) throws IOException {
log.debug("onConnect");

outbound.sendMessage("0{\"sid\":\"" + outbound.getSessionId() + "\",\"upgrades\":[],\"pingInterval\":25000,\"pingTimeout\":60000}");
}

Expand All @@ -58,11 +60,18 @@ public void onMessage(AtmosphereResource r, SocketIOSessionOutbound outbound, St

String name = msg.getName();

String spaceHome = r.getAtmosphereConfig().getInitParameter("SPACE_HOME", null);

if (spaceHome == null) {
log.error("SocketIOHandler on message error: SPACE_HOME must be setted in env");
return;
}

Message.Arg arg = msg.getArgs().get(0);

switch (name) {
case "term.open":
itermOpen(outbound, arg);
itermOpen(outbound, spaceHome, arg);
break;
case "term.input":
itermInput(outbound, arg);
Expand Down Expand Up @@ -103,11 +112,15 @@ private void itermResize(SocketIOSessionOutbound outbound, Message.Arg arg) {
}
}

private String getWorkdingDir(String spaceHome, String spaceKey) {
return format("%s/%s/%s", spaceHome, spaceKey, "/working-dir");
}

private String makeConnectorKey(String session, String termId) {
return session + "-" + termId;
}

public void itermOpen(SocketIOSessionOutbound outbound, Message.Arg arg) {
public void itermOpen(SocketIOSessionOutbound outbound, String spaceHome, Message.Arg arg) {
try {
Map<String, String> envs = Maps.newHashMap(System.getenv());

Expand All @@ -125,7 +138,7 @@ public void itermOpen(SocketIOSessionOutbound outbound, Message.Arg arg) {
outbound,
command,
envs,
null);
getWorkdingDir(spaceHome, arg.getSpaceKey()));

String key = makeConnectorKey(outbound.getSessionId(), arg.getId());

Expand Down