Update event names

This commit is contained in:
Jonathan Leibiusky @xetorthio
2017-07-24 14:55:17 -03:00
parent fd7441943d
commit 8424479e76
6 changed files with 32 additions and 19 deletions

View File

@@ -32,12 +32,12 @@ func WS(so socketio.Socket) {
core.SessionClose(session)
})
so.On("terminal in", func(name, data string) {
so.On("instance terminal in", func(name, data string) {
// User wrote something on the terminal. Need to write it to the instance terminal
core.InstanceWriteToTerminal(session.Id, name, data)
})
so.On("viewport resize", func(cols, rows uint) {
so.On("instance viewport resize", func(cols, rows uint) {
// User resized his viewport
core.ClientResizeViewPort(client, cols, rows)
})

View File

@@ -170,7 +170,6 @@ func (p *pwd) InstanceDelete(session *types.Session, instance *types.Instance) e
conn := getInstanceTermConn(session.Id, instance.Name)
if conn != nil {
conn.Close()
delete(terms[instance.SessionId], instance.Name)
}
err := p.docker.DeleteContainer(instance.Name)
if err != nil && !strings.Contains(err.Error(), "No such container") {
@@ -180,7 +179,6 @@ func (p *pwd) InstanceDelete(session *types.Session, instance *types.Instance) e
p.event.Emit(event.INSTANCE_DELETE, session.Id, instance.Name)
delete(session.Instances, instance.Name)
if err := p.storage.InstanceDelete(session.Id, instance.Name); err != nil {
return err
}

View File

@@ -14,7 +14,7 @@ import (
"github.com/play-with-docker/play-with-docker/docker"
"github.com/play-with-docker/play-with-docker/event"
"github.com/play-with-docker/play-with-docker/pwd/types"
"github.com/twinj/uuid"
"github.com/rs/xid"
)
var preparedSessions = map[string]bool{}
@@ -44,7 +44,7 @@ func (p *pwd) SessionNew(duration time.Duration, stack, stackName, imageName str
defer observeAction("SessionNew", time.Now())
s := &types.Session{}
s.Id = uuid.NewV4().String()
s.Id = xid.New().String()
s.Instances = map[string]*types.Instance{}
s.CreatedAt = time.Now()
s.ExpiresAt = s.CreatedAt.Add(duration)
@@ -186,7 +186,12 @@ func (p *pwd) SessionDeployStack(s *types.Session) error {
func (p *pwd) SessionGet(sessionId string) *types.Session {
defer observeAction("SessionGet", time.Now())
s, _ := p.storage.SessionGet(sessionId)
s, err := p.storage.SessionGet(sessionId)
if err != nil {
log.Println(err)
return nil
}
if _, err := p.prepareSession(s); err != nil {
log.Println(err)

View File

@@ -12,7 +12,7 @@ import (
"github.com/gorilla/securecookie"
"github.com/play-with-docker/play-with-docker/config"
"github.com/twinj/uuid"
"github.com/rs/xid"
)
func GetGoogleRecaptchaSiteKey() string {
@@ -79,7 +79,7 @@ func IsHuman(req *http.Request, rw http.ResponseWriter) bool {
return false
}
encoded, _ := s.Encode("session_id", uuid.NewV4().String())
encoded, _ := s.Encode("session_id", xid.New().String())
http.SetCookie(rw, &http.Cookie{
Name: "session_id",
Value: encoded,

View File

@@ -112,7 +112,20 @@ func (store *storage) InstanceCreate(sessionId string, instance *types.Instance)
}
func (store *storage) InstanceDelete(sessionId, name string) error {
panic("not implemented")
store.rw.Lock()
defer store.rw.Unlock()
s, found := store.db[sessionId]
if !found {
return fmt.Errorf("Session %s", notFound)
}
if _, found := s.Instances[name]; !found {
return nil
}
delete(s.Instances, name)
return store.save()
}
func (store *storage) SessionCount() (int, error) {

View File

@@ -81,7 +81,7 @@
}
$scope.resize = function(geometry) {
$scope.socket.emit('viewport resize', geometry.cols, geometry.rows);
$scope.socket.emit('instance viewport resize', geometry.cols, geometry.rows);
}
KeyboardShortcutService.setResizeFunc($scope.resize);
@@ -163,7 +163,7 @@
$scope.builderTerminal.write(data);
});
socket.on('terminal out', function(name, data) {
socket.on('instance terminal out', function(name, data) {
var instance = $scope.idx[name];
if (!instance) {
@@ -183,10 +183,7 @@
$scope.isAlive = false;
});
socket.on('viewport', function(rows, cols) {
});
socket.on('new instance', function(name, ip, hostname) {
socket.on('instance new', function(name, ip, hostname) {
$scope.upsertInstance({ name: name, ip: ip, hostname: hostname });
$scope.$apply(function() {
if ($scope.instances.length == 1) {
@@ -195,12 +192,12 @@
});
});
socket.on('delete instance', function(name) {
socket.on('instance delete', function(name) {
$scope.removeInstance(name);
$scope.$apply();
});
socket.on('viewport resize', function(cols, rows) {
socket.on('instance viewport resize', function(cols, rows) {
// viewport has changed, we need to resize all terminals
$scope.instances.forEach(function(instance) {
@@ -342,7 +339,7 @@
}, 4);
term.on('data', function(d) {
$scope.socket.emit('terminal in', instance.name, d);
$scope.socket.emit('instance terminal in', instance.name, d);
});
instance.term = term;