Browse Source

Allow slashes unquoted in room names. This brings nested rooms.

pull/194/head
Simon Eisenmann 10 years ago
parent
commit
e0fa8c8b43
  1. 6
      src/app/spreed-webrtc-server/main.go
  2. 2
      static/js/app.js
  3. 45
      static/js/services/resturl.js
  4. 11
      static/js/services/rooms.js

6
src/app/spreed-webrtc-server/main.go

@ -352,6 +352,8 @@ func runner(runtime phoenix.Runtime) error { @@ -352,6 +352,8 @@ func runner(runtime phoenix.Runtime) error {
r.Handle("/robots.txt", http.StripPrefix(config.B, http.FileServer(http.Dir(path.Join(rootFolder, "static")))))
r.Handle("/favicon.ico", http.StripPrefix(config.B, http.FileServer(http.Dir(path.Join(rootFolder, "static", "img")))))
r.Handle("/ws", makeWSHandler(statsManager, sessionManager, codec, channellingAPI))
// Simple room handler.
r.HandleFunc("/{room}", httputils.MakeGzipHandler(roomHandler))
// Add API end points.
@ -382,6 +384,10 @@ func runner(runtime phoenix.Runtime) error { @@ -382,6 +384,10 @@ func runner(runtime phoenix.Runtime) error {
}
}
// Map everything else to a room when it is a GET.
rooms := r.PathPrefix("/").Methods("GET").Subrouter()
rooms.HandleFunc("/{room:.*}", httputils.MakeGzipHandler(roomHandler))
return runtime.Start()
}

2
static/js/app.js

@ -154,7 +154,7 @@ define([ @@ -154,7 +154,7 @@ define([
$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|tel|file|filesystem|blob):/);
$compileProvider.imgSrcSanitizationWhitelist(/^\s*(https?|ftp|file|filesystem|blob):|data:image\//);
// Setup routing
$routeProvider.when("/:room", {});
$routeProvider.when("/:room*", {});
// Use HTML5 routing.
$locationProvider.html5Mode(true);
}]);

45
static/js/services/resturl.js

@ -20,21 +20,42 @@ @@ -20,21 +20,42 @@
*/
"use strict";
define([
], function() {
define(["underscore"], function(_) {
// restURL
return ["globalContext", "$window", function(context, $window) {
return {
room: function(id) {
id = $window.encodeURIComponent(id);
return $window.location.protocol + '//' + $window.location.host + context.Cfg.B + id;
},
buddy: function(id) {
return $window.location.protocol + '//' + $window.location.host + context.Cfg.B + "static/img/buddy/s46/" + id;
},
api: function(path) {
return (context.Cfg.B || "/") + "api/v1/" + path;
var RestURL = function() {};
RestURL.prototype.room = function(name) {
var url = this.encodeRoomURL(name);
return $window.location.protocol + '//' + $window.location.host + context.Cfg.B + url;
};
RestURL.prototype.buddy = function(id) {
return $window.location.protocol + '//' + $window.location.host + context.Cfg.B + "static/img/buddy/s46/" + id;
};
RestURL.prototype.api = function(path) {
return (context.Cfg.B || "/") + "api/v1/" + path;
};
RestURL.prototype.encodeRoomURL = function(name, prefix) {
// Split parts so slashes are allowed.
var parts = name.split("/");
var url = [];
if (typeof prefix !== "undefined") {
url.push(prefix);
}
// Allow some thing in room name parts.
_.each(parts, function(p) {
p = $window.encodeURIComponent(p);
p = p.replace(/^%40/, "@");
p = p.replace(/^%24/, "$");
p = p.replace(/^%2B/, "+");
url.push(p);
});
if (url.length > 1 && url[url.length-1] === "") {
// Remove trailing slash if any.
url.pop();
}
return url.join("/");
};
return new RestURL();
}];
});

11
static/js/services/rooms.js

@ -103,7 +103,7 @@ define([ @@ -103,7 +103,7 @@ define([
currentRoom = room;
if (priorRoom) {
priorRoomName = priorRoom.Name;
console.log("Left room", priorRoom.Name);
console.log("Left room", [priorRoom.Name]);
$rootScope.$broadcast("room.left", priorRoom.Name);
}
if (currentRoom) {
@ -212,13 +212,10 @@ define([ @@ -212,13 +212,10 @@ define([
return canJoinRooms;
},
joinByName: function(name, replace) {
name = $window.encodeURIComponent(name);
name = name.replace(/^%40/, "@");
name = name.replace(/^%24/, "$");
name = name.replace(/^%2B/, "+");
var url = restURL.encodeRoomURL(name, "");
// Apply new URL.
safeApply($rootScope, function(scope) {
$location.path("/" + name);
$location.path(url);
if (replace) {
$location.replace();
}

Loading…
Cancel
Save