Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented logic for unique rooms #820

Merged
merged 5 commits into from
Jul 7, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/editor/Collaboration.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,23 @@ define(function (require, exports, module) {
// immediately ask for camera access
autoRequestMedia: false
});
//To be moved to the bramble API.
var hash = window.location.hash.replace(/^#/, "");
var m = /&?collaboration=([^&]*)/.exec(hash);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this regex looks wrong, window.location.hash returns a fragment id not the querystring. Your regex seems to be dealing with querystrings. If it is meant to be on the querystring, do something like:

var query = (new URL(window.location.href)).searchParams;
this.room = query.collaboration || <random string>;

Copy link
Author

@hkirat hkirat Jul 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to be working.
I think it has to do with the fact that our url is
http://localhost:8000/src/hosted.html?collaboration=asdds
and not
http://localhost:8000/src/hosted.html/?collaboration=asdds

Opening
http://localhost:8000/src/hosted.html/?collaboration=asdds
doesn't seem to open hosted.html.

Another similar approach I found is :
URLSearchParams

var params = window.location.href.split("?").pop();
this.room = new URLSearchParams(params).get("collaboration") || Math.random().toString(36).substring(7);
        

Copy link

@gideonthomas gideonthomas Jul 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we want to try to minimize string manipulation in urls as much as possible.

I think I made a mistake in the code. Here's what it's supposed to be:

var query = (new URL(window.location.href)).searchParams;
this.room = query.get("collaboration") || <random string>;

if(m && m[1]) {
this.room = m[1];
} else {
this.room = Math.random().toString(36).substring(7);
}
console.log("Link -> http://localhost:8000/src/hosted.html#?collaboration=" + this.room);
this.webrtc = webrtc;
this.pending = []; // pending clients that need to be initialized.
this.changing = false;
};

Collaboration.prototype.init = function(codemirror) {
var self = this;
this.webrtc.joinRoom('thimble', function() {
this.webrtc.joinRoom(this.room, function() {
self.codemirror = codemirror;
self.webrtc.sendToAll("new client", {});
self.webrtc.on("createdPeer", function(peer) {
Expand Down
8 changes: 7 additions & 1 deletion src/hosted.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,14 @@
}

function load(Bramble) {
var hash = window.location.hash.replace(/^#/, "");
var m = /&?collaboration=([^&]*)/.exec(hash);
var url = "index.html";
if(m && m[1]) {
url = url + "#&collaboration=" + m[1];
}
Bramble.load("#bramble",{
url: "index.html",
url: url,
useLocationSearch: true
});

Expand Down