Merge pull request #170 from taigaio/events-disable-and-relative-url

Add the ability to disable events and use relative url in config.
stable
David Barragán Merino 2014-11-24 18:36:01 +01:00
commit 63d6f4c829
3 changed files with 18 additions and 3 deletions

View File

@ -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)

View File

@ -23,6 +23,7 @@ nl2br = (str) =>
breakTag = '<br />'
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)

View File

@ -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,