restore CHANNEL_PREFIX, but check if it is already present
This commit is contained in:
parent
1951784c28
commit
5130726389
|
@ -93,14 +93,12 @@ require 'travis/model'
|
||||||
return if @get('subscribed')
|
return if @get('subscribed')
|
||||||
@set('subscribed', true)
|
@set('subscribed', true)
|
||||||
if Travis.pusher
|
if Travis.pusher
|
||||||
prefix = if @get('repo.private') then 'private-' else ''
|
|
||||||
Travis.pusher.subscribe "#{prefix}job-#{@get('id')}",
|
Travis.pusher.subscribe "#{prefix}job-#{@get('id')}",
|
||||||
|
|
||||||
unsubscribe: ->
|
unsubscribe: ->
|
||||||
return unless @get('subscribed')
|
return unless @get('subscribed')
|
||||||
@set('subscribed', false)
|
@set('subscribed', false)
|
||||||
if Travis.pusher
|
if Travis.pusher
|
||||||
prefix = if @get('repo.private') then 'private-' else ''
|
|
||||||
Travis.pusher.unsubscribe "job-#{@get('id')}"
|
Travis.pusher.unsubscribe "job-#{@get('id')}"
|
||||||
|
|
||||||
onStateChange: (->
|
onStateChange: (->
|
||||||
|
|
|
@ -4,6 +4,7 @@ Travis.Pusher = (key) ->
|
||||||
|
|
||||||
$.extend Travis.Pusher,
|
$.extend Travis.Pusher,
|
||||||
CHANNELS: ['common']
|
CHANNELS: ['common']
|
||||||
|
CHANNEL_PREFIX: ''
|
||||||
ENCRYPTED: false
|
ENCRYPTED: false
|
||||||
|
|
||||||
$.extend Travis.Pusher.prototype,
|
$.extend Travis.Pusher.prototype,
|
||||||
|
@ -26,14 +27,19 @@ $.extend Travis.Pusher.prototype,
|
||||||
@subscribe(channel) for channel in channels
|
@subscribe(channel) for channel in channels
|
||||||
|
|
||||||
subscribe: (channel) ->
|
subscribe: (channel) ->
|
||||||
|
channel = @prefix(channel)
|
||||||
console.log("subscribing to #{channel}")
|
console.log("subscribing to #{channel}")
|
||||||
unless @pusher?.channel(channel)
|
unless @pusher?.channel(channel)
|
||||||
@pusher.subscribe(channel).bind_all((event, data) => @receive(event, data))
|
@pusher.subscribe(channel).bind_all((event, data) => @receive(event, data))
|
||||||
|
|
||||||
unsubscribe: (channel) ->
|
unsubscribe: (channel) ->
|
||||||
|
channel = @prefix(channel)
|
||||||
console.log("unsubscribing from #{channel}")
|
console.log("unsubscribing from #{channel}")
|
||||||
@pusher.unsubscribe(channel) if @pusher?.channel(channel)
|
@pusher.unsubscribe(channel) if @pusher?.channel(channel)
|
||||||
|
|
||||||
|
prefix: (channel) ->
|
||||||
|
"#{Travis.Pusher.CHANNEL_PREFIX}#{channel}" unless channel.indexOf(Travis.Pusher.CHANNEL_PREFIX) == 0
|
||||||
|
|
||||||
# process pusher messages in batches every 5 minutes when the page is hidden
|
# process pusher messages in batches every 5 minutes when the page is hidden
|
||||||
processingIntervalWhenHidden: 1000 * 60 * 5
|
processingIntervalWhenHidden: 1000 * 60 * 5
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user