Add the ability to disable events and use relative url in config.

stable
Andrey Antukh 2014-11-19 19:34:03 +01:00
parent 32278f5bb0
commit cc17743045
3 changed files with 18 additions and 3 deletions

View File

@ -20,6 +20,7 @@
### ###
taiga = @.taiga taiga = @.taiga
startswith = @.taiga.startswith
module = angular.module("taigaEvents", []) module = angular.module("taigaEvents", [])
@ -41,7 +42,18 @@ class EventsService
setupConnection: -> setupConnection: ->
@.stopExistingConnection() @.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 = new @win.WebSocket(url)
@.ws.addEventListener("open", @.onOpen) @.ws.addEventListener("open", @.onOpen)

View File

@ -23,6 +23,7 @@ nl2br = (str) =>
breakTag = '<br />' breakTag = '<br />'
return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag + '$2') return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag + '$2')
bindOnce = (scope, attr, continuation) => bindOnce = (scope, attr, continuation) =>
val = scope.$eval(attr) val = scope.$eval(attr)
if val != undefined if val != undefined
@ -106,9 +107,11 @@ joinStr = (str, coll) ->
debounce = (wait, func) -> debounce = (wait, func) ->
return _.debounce(func, wait, {leading: true, trailing: false}) return _.debounce(func, wait, {leading: true, trailing: false})
debounceLeading = (wait, func) -> debounceLeading = (wait, func) ->
return _.debounce(func, wait, {leading: false, trailing: true}) return _.debounce(func, wait, {leading: false, trailing: true})
startswith = (str1, str2) -> startswith = (str1, str2) ->
return _.str.startsWith(str1, str2) return _.str.startsWith(str1, str2)

View File

@ -1,7 +1,7 @@
{ {
"api": "http://localhost:8000/api/v1/", "api": "http://localhost:8000/api/v1/",
"eventsUrl": "ws://localhost:8888/events", "eventsUrl": null,
"debug": "true", "debug": true,
"publicRegisterEnabled": true, "publicRegisterEnabled": true,
"feedbackEnabled": true, "feedbackEnabled": true,
"privacyPolicyUrl": null, "privacyPolicyUrl": null,