-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocket-ext.js
More file actions
64 lines (48 loc) · 2.05 KB
/
socket-ext.js
File metadata and controls
64 lines (48 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"use strict";
var ERROR = require("http-error");
module.exports = function setup(options, imports, register) {
var IDE = imports.ide.getServer();
var SESSION = imports.session;
var PERMISSIONS = imports["workspace-permissions"];
var TRANSPORT = imports["smith.transport.server"];
TRANSPORT.on("connect", function(connection) {
connection.on("message", function(message) {
if (message.command === "attach" && typeof message.workspaceId !== "undefined") {
getSession(message.sessionId, function(err, session) {
if (err) {
return connection.send({
"type": "error",
"code": err.code,
"message": err.message
});
}
message.session = session;
var uid = session.uid || session.anonid;
PERMISSIONS.getPermissions(uid, message.workspaceId, "cloud9.socket", function(err, userPermissions) {
if (err) {
connection.send(err.toJSON ? err.toJSON() : {
"type": "error",
"code": err.code || 500,
"message": err.message || err
});
}
IDE.addUser(uid, userPermissions);
IDE.addClientConnection(uid, connection, message);
});
});
}
});
});
function getSession(sessionId, callback) {
SESSION.get(sessionId, function(err, session) {
if (err)
return callback(new ERROR.InternalServerError(err));
if (!session || !(session.uid || session.anonid))
return callback(new ERROR.Unauthorized("Session ID missing"));
return callback(null, session);
});
};
register(null, {
"workspace-socket": {}
});
};