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 1 commit
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
10 changes: 9 additions & 1 deletion src/editor/Collaboration.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,22 @@ define(function (require, exports, module) {
// immediately ask for camera access
autoRequestMedia: false
});
var hash = location.hash.replace(/^#/, "");

Choose a reason for hiding this comment

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

it's safer to include window.location here vs. just location

Choose a reason for hiding this comment

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

Can you add a comment above saying that this is only temporary and it needs to be moved to the Bramble API?
Also, can you file a follow up issue in Thimble for this?

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("brackets-"+this.room, function() {

Choose a reason for hiding this comment

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

I don't think we need to add the brackets prefix here. Let's force the hosting app to enforce uniqueness of rooms (and namespacing if necessary).

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 = location.hash.replace(/^#/, "");

Choose a reason for hiding this comment

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

In the issue you file from the comment above, can you link to this piece of code as well so that we don't forget to change it as well when we move to the bramble api.

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