@@ -9,20 +9,21 @@ var _ = require('underscore')
99class PlaybackInfo extends BaseObject {
1010 constructor ( ) {
1111 this . data = {
12- 'chunks' : { 'recvCDN' : 0 , 'recvP2P' : 0 , 'sentP2P' : 0 } ,
12+ 'chunks' : { chunksFromCDN : 0 , chunksFromP2P : 0 , chunksSent : 0 } ,
1313 'bufferLength' : 0
1414 }
1515 }
1616
1717 setMain ( main ) {
1818 this . main = main
19+ this . triggerStats ( { status : "on" } )
20+ this . updateData ( { delay : this . main . el . getDelay ( ) } )
1921 this . data . delay = this . main . el . getDelay ( )
2022 this . addEventListeners ( )
21- this . bufferLengthTimer = setInterval ( ( ) => this . updateBufferLength ( ) , 1000 )
22- this . triggerStats ( { status : "on" } )
2323 }
2424
2525 updateData ( metrics ) {
26+ this . triggerStats ( metrics )
2627 this . data = _ . extend ( this . data , metrics )
2728 console . log ( this . data )
2829 }
@@ -38,42 +39,25 @@ class PlaybackInfo extends BaseObject {
3839 }
3940
4041 addEventListeners ( ) {
41- this . listenTo ( this . main . resourceRequester . p2pManager . swarm , "swarm:sizeupdate" , ( event ) => this . updateSwarmSize ( event ) )
42+ this . listenTo ( this . main . resourceRequester . p2pManager . swarm , "swarm:sizeupdate" , ( event ) => this . updateData ( event ) )
4243 this . listenTo ( this . main . uploadHandler , 'uploadhandler:update' , ( event ) => this . updateUploadSlots ( event ) )
4344 Clappr . Mediator . on ( this . main . uniqueId + ':fragmentloaded' , ( ) => this . onFragmentLoaded ( ) )
4445 }
4546
4647 onFragmentLoaded ( ) {
4748 var bitrate = Math . floor ( this . main . getCurrentBitrate ( ) / 1000 )
49+ var bufferLength = this . main . el . globoGetbufferLength ( )
4850 bitrate = ! _ . isNaN ( bitrate ) ? bitrate : 'UNKNOWN'
49- var data = { state : this . main . currentState , currentBitrate : bitrate }
50- this . updateData ( data )
51- this . triggerStats ( data )
52- }
53-
54- updateSwarmSize ( data ) {
55- this . triggerStats ( data )
51+ bufferLength = ! _ . isNaN ( bufferLength ) ? bufferLength : 0
52+ var data = { state : this . main . currentState , currentBitrate : bitrate , bufferLength : bufferLength }
5653 this . updateData ( data )
5754 }
5855
59- updateBufferLength ( ) {
60- this . bufferLength = this . main . el . globoGetbufferLength ( ) || 0
61- var data = { bufferLength : this . bufferLength }
62- this . updateData ( data )
63- this . triggerStats ( data )
64- }
65-
6656 updateChunkStats ( method = null ) {
67- console . log ( "update chunk stats" , method )
68- if ( method === "p2p" ) this . data . chunks . recvP2P ++
69- else if ( method === "cdn" ) this . data . chunks . recvCDN ++
70- else if ( method === "p2psent" ) this . data . chunks . sentP2P ++
71- var stats = {
72- chunksFromP2P : this . data . chunks . recvP2P ,
73- chunksFromCDN : this . data . chunks . recvCDN ,
74- chunksSent : this . data . chunks . sentP2P
75- }
76- this . triggerStats ( stats )
57+ if ( method === "p2p" ) this . data . chunks . chunksFromP2P ++
58+ else if ( method === "cdn" ) this . data . chunks . chunksFromCDN ++
59+ else if ( method === "p2psent" ) this . data . chunks . chunksSent ++
60+ this . triggerStats ( this . data . chunks )
7761 }
7862
7963 updateUploadSlots ( metrics ) {
0 commit comments