Skip to content
This repository was archived by the owner on Nov 7, 2020. It is now read-only.

Commit

Permalink
Merge pull request #164 from drewww/session-routing-debug
Browse files Browse the repository at this point in the history
Session routing debug
  • Loading branch information
drewww committed Oct 8, 2013
2 parents e91806c + eb0dc71 commit 6c6aa9d
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 12 deletions.
7 changes: 5 additions & 2 deletions lib/server-models.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,11 +423,13 @@ exports.ServerSession = client_models.Session.extend({
obj["userId"] = user.id;
}
this.set("hangout-pending", obj);
exports.logger.debug("set hangout pending: " + JSON.stringify(this.get("hangout-pending")));
return true;
}
},

isHangoutPending: function() {
exports.logger.debug("checking hangout pending, field: " + JSON.stringify(this.get("hangout-pending")));
if(_.isNull(this.get("hangout-pending"))) {
return false;
} else {
Expand All @@ -453,6 +455,7 @@ exports.ServerSession = client_models.Session.extend({
},

setHangoutUrl: function(url) {
exports.logger.debug("current: " + this.get("hangout-url") + "; setting to: " + url);
if(_.isNull(this.get("hangout-url"))) {
exports.logger.debug("setting hangout url: " + url + " and clearing pending. notifying listeners.");
this.set("hangout-url", url);
Expand All @@ -467,7 +470,7 @@ exports.ServerSession = client_models.Session.extend({
// the only time I think this will happen is if someone fails to create a hangout within
// the creation timeout period (about 30 seconds right now) and then finally does succeed,
// and their new hangout tries to register.
logger.warn("Got attempt to set hangout-url, with url already valid. Cur url: " + this.get("hangout-url") + "; attempted: " + url);
exports.logger.warn("Got attempt to set hangout-url, with url already valid. Cur url: " + this.get("hangout-url") + "; attempted: " + url);

// TODO it would be nice if they got some sort of warning here, but we don't have a good way
// to talk back to their hangout.
Expand All @@ -484,7 +487,7 @@ exports.ServerSession = client_models.Session.extend({
this.collection.event.broadcast("session-participants", {id:this.id, participantIds:this.get("connectedParticipantIds")});
}

exports.logger.debug("hangoutConnected: " + this.get("hangoutConnected"));
exports.logger.debug("setting connected participants to: " + participantIds);
},

heartbeat: function() {
Expand Down
34 changes: 27 additions & 7 deletions lib/unhangout-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,8 @@ exports.UnhangoutServer.prototype = {
// than nothing.
this.express.get("/session/:id", _.bind(function(req, res) {
var session = getSession(req.params.id, this.events, this.permalinkSessions);

logger.info("session: " + JSON.stringify(session));

if(session) {
// three options at this point:
// 1. the session is already running and has a hangout link populated -> redirect to hangout
Expand All @@ -845,7 +846,7 @@ exports.UnhangoutServer.prototype = {
// to generate the session and have that session phone home.

if(session.getHangoutUrl()) {
logger.info("redirecting user to hangout: " + session.getHangoutUrl());
logger.info("redirecting user to existing hangout url: " + session.getHangoutUrl());

// append all the google hangout app info to enforce loading it on startup
res.redirect(session.getHangoutUrl());
Expand Down Expand Up @@ -1026,9 +1027,28 @@ exports.UnhangoutServer.prototype = {
}
}, this));

// this endpoint manually stops a shortcode session.
// we seem to occasionally get sessions that are broken and stay open when
// they're supposed to be closed. this lets us fix that issue.
// this checks global admin status, not per-shortcode admin status.
// we could at some point add this in to the permalink admin page, but I don't
// think people actually go back to that.
this.express.post("/h/:code/stop", ensureAdmin, _.bind(function(req, res) {
var session = this.permalinkSessions.find(function(s) {
return s.get("shortCode")==req.params.code;
});

if(_.isUndefined(session)) {
logger.warn("sess:unknown (stop)" + JSON.stringify(req.body));
res.status(404);
res.send();
return;
}


// this will cascasde to trigger hangout-stopped, since we're hard-triggering a stop.
session.set("hangoutConnected", false);
res.redirect("/admin");
}, this));


// all messages from the hangout app running in each of the active hangouts
Expand Down Expand Up @@ -1081,15 +1101,17 @@ exports.UnhangoutServer.prototype = {
// setHangoutUrl piece because the hangout already has a url.
case "loaded":
if(session && "url" in req.body) {
logger.info("session:" + session.id + ":loaded\tparticipant:" + JSON.stringify(req.body.participant));
logger.info("session:" + session.id + ":loaded\tparticipant:" + JSON.stringify(req.body.participant) + "\tparticipants: " + JSON.stringify(req.body.participants) + "\tkey: " + req.params.id + "\turl: " + req.body.url);

// get the post data; we're expecting the url to be in the payload.
var url = req.body.url;
logger.info("cur session url: " + session.getHangoutUrl() + "; setting to: " + url);

// the session will ignore this if it already has a url.
var fullURL = url + generateSessionHangoutGDParam(session, this.options);
logger.debug("redirecting to: " + fullURL);
// logger.debug("(trying to) set hangout url to: " + fullURL);
session.setHangoutUrl(fullURL);

res.status(200);
res.send();
} else {
Expand Down Expand Up @@ -1117,8 +1139,6 @@ exports.UnhangoutServer.prototype = {
// and if their id is not tracked in users, add them in. This will help us rendering
// their pictures elsewhere in the app without much trouble.
_.each(req.body.participants, _.bind(function(participant) {
logger.info("participant: " + JSON.stringify(participant));
logger.debug("found? " + this.users.get(participant.person.id));
if(_.isUndefined(this.users.get(participant.person.id))) {
logger.debug("creating new user object");

Expand Down
5 changes: 5 additions & 0 deletions public/css/screen.css
Original file line number Diff line number Diff line change
Expand Up @@ -866,3 +866,8 @@ tr:nth-child(even) {
background-color: #57AF57;
border-radius: 3px;
}

/* line 965, ../../sass/screen.scss */
td form {
margin: 0px;
}
7 changes: 6 additions & 1 deletion public/hangout/hangout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,15 @@ function init() {
function loaded(eventObj) {
var allParticipantIds = _.map(gapi.hangout.getParticipants(), function(p) {
return p.person.id;
});
$.post(serverUrl, {
type: "loaded",
url: gapi.hangout.getHangoutUrl(),
participant: localGoogleId
participant: localGoogleId,
participants: allParticipantIds,
}).done(function() {
console.log("loaded success!");
}).fail(function() {
Expand Down
4 changes: 4 additions & 0 deletions sass/screen.scss
Original file line number Diff line number Diff line change
Expand Up @@ -960,4 +960,8 @@ tr:nth-child(even) {
background-color: #57AF57;
border-radius: 3px;
}
}

td form {
margin: 0px;
}
13 changes: 11 additions & 2 deletions views/admin.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,23 @@
</table>

<table id="permalinks">
<tr><th>shortcode</th><th># ppl connected</th><th>total seconds active</th><th># hangouts created</th><th>user seconds active</th></tr>
<tr><th>shortcode</th><th># ppl connected</th><th>total seconds active</th><th># hangouts created</th><th>actions</th></tr>
<% permalinkSessions.forEach(function(session) { %>
<tr>
<td><a href="/h/<%= session.get("shortCode") %>"><%= session.get("shortCode") %></a></td>
<td><%= session.get("connectedParticipantIds").length %></td>
<td><%= session.get("total-seconds") %></td>
<td><%= session.get("total-instances") %></td>
<td><%= session.get("user-seconds") %></td>
<td>
<div class="hide">
<%= JSON.stringify(session) %>
</div>
<% if(session.get("hangoutConnected")) { %>
<form action="/h/<%= session.get("shortCode") %>/stop" method="post">
<button type="submit" class="btn btn-danger btn-link">stop</submit>
</form>
<% } %>
</td>
</tr>
<% }) %>
</table>
Expand Down

0 comments on commit 6c6aa9d

Please sign in to comment.