Skip to content

Commit

Permalink
Merge pull request #29 from mediainbox/develop
Browse files Browse the repository at this point in the history
Added Debug info to Proxy Source and Memory chunk
  • Loading branch information
cdgraff authored Jun 9, 2017
2 parents 494ccb9 + f83290f commit 2227ad2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
14 changes: 12 additions & 2 deletions Gruntfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = (grunt) ->
grunt.initConfig
pkg: grunt.file.readJSON 'package.json'
coffee:
coffee_to_js:
default:
options:
bare: true
sourceMap: true
Expand All @@ -11,6 +11,15 @@ module.exports = (grunt) ->
src: ["src/**/*.coffee","streamer.coffee","runner.coffee","util.coffee","util/*.coffee"]
dest: 'js/'
ext: ".js"
'no-sourcemaps':
options:
bare: true
sourceMap: false
expand: true
flatten: false
src: ["src/**/*.coffee","streamer.coffee","runner.coffee","util.coffee","util/*.coffee"]
dest: 'js/'
ext: ".js"

copy:
copy_slave_worker:
Expand All @@ -19,4 +28,5 @@ module.exports = (grunt) ->
grunt.loadNpmTasks 'grunt-contrib-coffee'
grunt.loadNpmTasks 'grunt-contrib-copy'

grunt.registerTask 'default', ['coffee','copy']
grunt.registerTask 'default', ['coffee:default','copy']
grunt.registerTask 'build:no-sourcemaps', ['coffee:no-sourcemaps','copy']
3 changes: 3 additions & 0 deletions src/streammachine/rewind/memory_store.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
bs = require 'binary-search'

debug = require("debug")("sm:rewind:memory_store")

module.exports = class MemoryStore extends require("./base_store")
constructor: (@max_length = null) ->
@buffer = []
Expand Down Expand Up @@ -123,6 +125,7 @@ module.exports = class MemoryStore extends require("./base_store")

else
# need to insert in the middle.
debug "Push in the middle not implemented #{cts}, #{fb}, #{lb}"
console.error "PUSH IN MIDDLE NOT IMPLEMENTED", cts, fb, lb

@_truncate()
Expand Down
26 changes: 16 additions & 10 deletions src/streammachine/sources/proxy.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -88,30 +88,35 @@ module.exports = class ProxySource extends require("./base")

_reconnect = _.once =>
unless @_in_disconnect
debug "Engaging reconnect logic"
setTimeout ( => @connect() ), 5000
msWaitToConnect = 5000
debug "Engaging reconnect logic to #{@url} in #{msWaitToConnect}ms"

debug "Lost or failed to make connection to #{@url}. Retrying in one second."
@connected = false

# unpipe everything
@icecast?.removeAllListeners()
@icecast = null

setTimeout ( => @connect() ), msWaitToConnect

ireq = Icy.get url_opts, (ice) =>
debug "Connected to Icecast client on #{@url}"

if ice.statusCode == 302
@url = ice.headers.location
@icecast = ice

@icecast.once "end", =>
debug "Got end event"
debug "Got Icecast end event"
_reconnect()

@icecast.once "close", =>
debug "Got close event"
debug "Got Icecast close event"
_reconnect()

@icecast.on "metadata", (data) =>
debug "Received Icecast metadata"

unless @_in_disconnect
meta = Icy.parse(data)

Expand All @@ -126,11 +131,6 @@ module.exports = class ProxySource extends require("./base")
# incoming -> Parser
@icecast.on "data", (chunk) => @parser.write chunk

# return with success
@connected = true
@connected_at = new Date()
@emit "connect"

_checkStatus = () =>
debug "Checking last_ts: #{@last_ts}"
return unless @connected and not @_in_disconnect
Expand All @@ -140,6 +140,12 @@ module.exports = class ProxySource extends require("./base")
ireq.end()
return _reconnect()
setTimeout _checkStatus, 30000

# return with success
@connected = true
@connected_at = new Date()
@emit "connect"

setTimeout _checkStatus, 30000

ireq.once "error", (err) =>
Expand Down

0 comments on commit 2227ad2

Please sign in to comment.