From cc177430451dc48656c0c8f4cd71afbffbc04a60 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 19 Nov 2014 19:34:03 +0100 Subject: [PATCH] Add the ability to disable events and use relative url in config. --- app/coffee/modules/events.coffee | 14 +++++++++++++- app/coffee/utils.coffee | 3 +++ conf/main.example.json | 4 ++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/coffee/modules/events.coffee b/app/coffee/modules/events.coffee index 08445607..f167fcfe 100644 --- a/app/coffee/modules/events.coffee +++ b/app/coffee/modules/events.coffee @@ -20,6 +20,7 @@ ### taiga = @.taiga +startswith = @.taiga.startswith module = angular.module("taigaEvents", []) @@ -41,7 +42,18 @@ class EventsService setupConnection: -> @.stopExistingConnection() - url = @config.get("eventsUrl", "ws://localhost:8888/events") + url = @config.get("eventsUrl") + + # This allows disable events in case + # url is not found on the configuration. + return if not url + + # This allows relative urls in configuration. + if not startswith(url, "ws:") and not startswith(url, "wss:") + loc = @win.location + scheme = if loc.protocol == "https:" then "wss:" else "ws:" + path = _.str.ltrim(url, "/") + url = "#{scheme}//#{loc.host}/#{path}" @.ws = new @win.WebSocket(url) @.ws.addEventListener("open", @.onOpen) diff --git a/app/coffee/utils.coffee b/app/coffee/utils.coffee index b7150637..455211bf 100644 --- a/app/coffee/utils.coffee +++ b/app/coffee/utils.coffee @@ -23,6 +23,7 @@ nl2br = (str) => breakTag = '
' return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag + '$2') + bindOnce = (scope, attr, continuation) => val = scope.$eval(attr) if val != undefined @@ -106,9 +107,11 @@ joinStr = (str, coll) -> debounce = (wait, func) -> return _.debounce(func, wait, {leading: true, trailing: false}) + debounceLeading = (wait, func) -> return _.debounce(func, wait, {leading: false, trailing: true}) + startswith = (str1, str2) -> return _.str.startsWith(str1, str2) diff --git a/conf/main.example.json b/conf/main.example.json index e40d5dcd..181dc694 100644 --- a/conf/main.example.json +++ b/conf/main.example.json @@ -1,7 +1,7 @@ { "api": "http://localhost:8000/api/v1/", - "eventsUrl": "ws://localhost:8888/events", - "debug": "true", + "eventsUrl": null, + "debug": true, "publicRegisterEnabled": true, "feedbackEnabled": true, "privacyPolicyUrl": null,