From e0fa8c8b43eb9dbbd918abc317fd8ebae449e956 Mon Sep 17 00:00:00 2001 From: Simon Eisenmann Date: Mon, 20 Apr 2015 18:08:59 +0200 Subject: [PATCH] Allow slashes unquoted in room names. This brings nested rooms. --- src/app/spreed-webrtc-server/main.go | 6 ++++ static/js/app.js | 2 +- static/js/services/resturl.js | 45 ++++++++++++++++++++-------- static/js/services/rooms.js | 11 +++---- 4 files changed, 44 insertions(+), 20 deletions(-) diff --git a/src/app/spreed-webrtc-server/main.go b/src/app/spreed-webrtc-server/main.go index 86a157a8..8ea32933 100644 --- a/src/app/spreed-webrtc-server/main.go +++ b/src/app/spreed-webrtc-server/main.go @@ -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 { } } + // 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() } diff --git a/static/js/app.js b/static/js/app.js index d63c58a0..989277bb 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -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); }]); diff --git a/static/js/services/resturl.js b/static/js/services/resturl.js index 381124c1..c585076c 100644 --- a/static/js/services/resturl.js +++ b/static/js/services/resturl.js @@ -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(); }]; }); diff --git a/static/js/services/rooms.js b/static/js/services/rooms.js index df99a0ca..94d0ba16 100644 --- a/static/js/services/rooms.js +++ b/static/js/services/rooms.js @@ -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([ 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(); }