set = ! saved.running;
} else {
throw new util.AssertionError("No saved status, and no startup._launch request; why did TogetherJS start?");
}
assert(session.identityId);
session.clientId = session.identityId + "." + sessionId;
if (set) {
storage.tab.set("status", {reason: TogetherJS.startup.reason, shareId: shareId, running: true, date: Date.now(), sessionId: sessionId});
}
session.isClient = isClient;
session.shareId = shareId;
session.emit("shareId");
def.resolve(session.shareId);
});
});
}
function initStartTarget() {
var id;
if (TogetherJS.startup.button) {
id = TogetherJS.startup.button.id;
if (id) {
storage.set("startTarget", id);
}
return;
}
storage.get("startTarget").then(function (id) {
var el = document.getElementById(id);
if (el) {
TogetherJS.startup.button = el;
}
});
}
session.start = function () {
initStartTarget();
initIdentityId().then(function () {
initShareId().then(function () {
readyForMessages = false;
openChannel();
require(["ui"], function (ui) {
TogetherJS.running = true;
ui.prepareUI();
require(features, function () {
$(function () {
peers = require("peers");
var startup = require("startup");
session.emit("start");
session.once("ui-ready", function () {
readyForMessages = true;
startup.start();
});
ui.activateUI();
TogetherJS.config.close("enableAnalytics");
if (TogetherJS.config.get("enableAnalytics")) {
require(["analytics"], function (analytics) {
analytics.activate();
});
}
peers._SelfLoaded.then(function () {
sendHello(false);
});
TogetherJS.emit("ready");
});
});
});
});
});
};
session.close = function (reason) {
TogetherJS.running = false;
var msg = {type: "bye"};
if (reason) {
msg.reason = reason;
}
session.send(msg);
session.emit("close");
var name = window.name;
storage.tab.get("status").then(function (saved) {
if (! saved) {
console.warn("No session information saved in", "status." + name);
} else {
saved.running = false;
saved.date = Date.now();
storage.tab.set("status", saved);
}
channel.close();
channel = null;
session.shareId = null;
session.emit("shareId");
TogetherJS.emit("close");
TogetherJS._teardown();
});
};
session.on("start", function () {
$(window).on("resize", resizeEvent);
if (includeHashInUrl) {
$(window).on("hashchange", hashchangeEvent);
}
});
session.on("close", function () {
$(window).off("resize", resizeEvent);
if (includeHashInUrl) {
$(window).off("hashchange", hashchangeEvent);
}
});
function hashchangeEvent() {