Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Commit

Permalink
create PlaybackInfo module (closes #93)
Browse files Browse the repository at this point in the history
  • Loading branch information
flavioribeiro committed Oct 12, 2014
1 parent 5c018fa commit ab3708d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var Settings = require('./settings')
var ResourceRequester = require('./resource_requester')
var UploadHandler = require('./upload_handler')
var Stats = require('./stats')
var PlaybackInfo = require('./playback_info')

var JST = require('./jst')
var HLS = require('./hls')
Expand All @@ -24,10 +25,11 @@ class P2PHLS extends HLS {
}

constructor(options) {
options.swfPath = "http://cdn.clappr.io/bemtv/latest/assets/P2PHLSPlayer.swf"
options.swfPath = "assets/P2PHLSPlayer.swf"
this.resourceRequester = new ResourceRequester({swarm: btoa(options.src), tracker: options.tracker})
this.uploadHandler = UploadHandler.getInstance()
this.stats = Stats.getInstance()
this.playbackInfo = PlaybackInfo.getInstance()
super(options)
}

Expand All @@ -51,6 +53,7 @@ class P2PHLS extends HLS {
bootstrap() {
super()
this.stats.setEmitter(this)
this.playbackInfo.setMain(this)
this.el.playerSetminBufferLength(6)
this.el.playerSetlowBufferLength(Settings.lowBufferLength)
}
Expand All @@ -64,6 +67,7 @@ class P2PHLS extends HLS {

requestResource(url) {
this.currentUrl = url
this.playbackInfo.addData({'segmentSize': this.getAverageSegmentSize()})
this.resourceRequester.p2pManager.swarm.avgSegmentSize = this.getAverageSegmentSize()
this.resourceRequester.requestResource(url, this.bufferLength, (chunk, method) => this.resourceLoaded(chunk, method))
}
Expand Down
31 changes: 31 additions & 0 deletions src/playback_info.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2014 Flávio Ribeiro <[email protected]>.
// All rights reserved.
// Use of this source code is governed by a Apache
// license that can be found in the LICENSE file.

var BaseObject = require('base_object')
var _ = require('underscore')

class PlaybackInfo extends BaseObject {
constructor() {
this.data = {}
}

setMain(main) {
this.main = main
this.listenTo(this.main, 'playback:stats:add', (metrics) => this.addData(metrics))
}

addData(metrics) {
this.data = _.extend(this.data, metrics)
}
}

PlaybackInfo.getInstance = function() {
if (this._instance === undefined) {
this._instance = new this()
}
return this._instance
}

module.exports = PlaybackInfo
2 changes: 1 addition & 1 deletion src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Settings {
Turn on/off statistics report for P2PHLSStats and
built-in Clappr stats module. If you're not using
P2PHLSStats, doesn't make sense to turn it on. */
Settings.statsReport = false
Settings.statsReport = true

/* logging
Turn on/off logging on browser's console on
Expand Down
2 changes: 0 additions & 2 deletions src/swarm_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
var BaseObject = require('base_object')
var _ = require('underscore')
var Settings = require('./settings')
var log = require('./log')


class SwarmUtils extends BaseObject {
constructor(swarm) {
Expand Down

0 comments on commit ab3708d

Please sign in to comment.