MCPcopy
hub / github.com/jsfiddle/togetherjs / initShareId

Function initShareId

togetherjs/session.js:274–368  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

272 initIdentityId.done = initIdentityId();
273
274 function initShareId() {
275 return util.Deferred(function (def) {
276 var hash = location.hash;
277 var shareId = session.shareId;
278 var isClient = true;
279 var set = true;
280 var sessionId;
281 session.firstRun = ! TogetherJS.startup.continued;
282 if (! shareId) {
283 if (TogetherJS.startup._joinShareId) {
284 // Like, below, this *also* means we got the shareId from the hash
285 // (in togetherjs.js):
286 shareId = TogetherJS.startup._joinShareId;
287 }
288 }
289 if (! shareId) {
290 // FIXME: I'm not sure if this will ever happen, because togetherjs.js should
291 // handle it
292 var m = /&?togetherjs=([^&]*)/.exec(hash);
293 if (m) {
294 isClient = ! m[1];
295 shareId = m[2];
296 var newHash = hash.substr(0, m.index) + hash.substr(m.index + m[0].length);
297 location.hash = newHash;
298 }
299 }
300 return storage.tab.get("status").then(function (saved) {
301 var findRoom = TogetherJS.config.get("findRoom");
302 TogetherJS.config.close("findRoom");
303 if (findRoom && saved && findRoom != saved.shareId) {
304 console.info("Ignoring findRoom in lieu of continued session");
305 } else if (findRoom && TogetherJS.startup._joinShareId) {
306 console.info("Ignoring findRoom in lieu of explicit invite to session");
307 }
308 if (findRoom && typeof findRoom == "string" && (! saved) && (! TogetherJS.startup._joinShareId)) {
309 isClient = true;
310 shareId = findRoom;
311 sessionId = util.generateId();
312 } else if (findRoom && (! saved) && (! TogetherJS.startup._joinShareId)) {
313 assert(findRoom.prefix && typeof findRoom.prefix == "string", "Bad findRoom.prefix", findRoom);
314 assert(findRoom.max && typeof findRoom.max == "number" && findRoom.max > 0,
315 "Bad findRoom.max", findRoom);
316 sessionId = util.generateId();
317 if (findRoom.prefix.search(/[^a-zA-Z0-9]/) != -1) {
318 console.warn("Bad value for findRoom.prefix:", JSON.stringify(findRoom.prefix));
319 }
320 getRoomName(findRoom.prefix, findRoom.max).then(function (shareId) {
321 // FIXME: duplicates code below:
322 session.clientId = session.identityId + "." + sessionId;
323 storage.tab.set("status", {reason: "joined", shareId: shareId, running: true, date: Date.now(), sessionId: sessionId});
324 session.isClient = true;
325 session.shareId = shareId;
326 session.emit("shareId");
327 def.resolve(session.shareId);
328 });
329 return;
330 } else if (TogetherJS.startup._launch) {
331 if (saved) {

Callers 1

session.jsFile · 0.85

Calls 2

getRoomNameFunction · 0.85
assertFunction · 0.50

Tested by

no test coverage detected