@gumlet/insights-js-core 1.1.4 → 1.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/release/gumlet-insights.min.js +2 -0
- package/build/release/gumlet-insights.min.js.LICENSE.txt +10 -0
- package/build/release/package.json +1 -0
- package/package.json +3 -2
- package/.github/workflows/main.yml +0 -87
- package/.gitlab-ci.yml +0 -54
- package/bitbucket-pipelines.yml +0 -35
- package/docs/payload-documentation.md +0 -72
- package/html/bitmovin.html +0 -82
- package/html/dashjs.html +0 -55
- package/html/hlsjs.html +0 -72
- package/html/html5.html +0 -59
- package/html/shaka.html +0 -102
- package/html/videojs.html +0 -67
- package/index.html +0 -73
- package/jest.config.js +0 -187
- package/js/adapters/Bitmovin7Adapter.js +0 -352
- package/js/adapters/BitmovinAdapter.js +0 -198
- package/js/adapters/DashjsAdapter.js +0 -140
- package/js/adapters/HTML5Adapter.js +0 -774
- package/js/adapters/HlsjsAdapter.js +0 -152
- package/js/adapters/ShakaAdapter.js +0 -81
- package/js/adapters/VideoJsAdapter.js +0 -455
- package/js/analyticsStateMachines/Bitmovin7AnalyticsStateMachine.js +0 -471
- package/js/analyticsStateMachines/BitmovinAnalyticsStateMachine.js +0 -299
- package/js/analyticsStateMachines/HTML5AnalyticsStateMachine.js +0 -443
- package/js/analyticsStateMachines/VideoJsAnalyticsStateMachine.js +0 -503
- package/js/cast/CastClient.js +0 -50
- package/js/cast/CastReceiver.js +0 -37
- package/js/core/AdapterFactory.js +0 -41
- package/js/core/Analytics.js +0 -1367
- package/js/core/AnalyticsStateMachineFactory.js +0 -36
- package/js/core/GumletInsightsExport.js +0 -81
- package/js/enums/CDNProviders.js +0 -11
- package/js/enums/Events.js +0 -32
- package/js/enums/GumletEnum.js +0 -19
- package/js/enums/MIMETypes.js +0 -30
- package/js/enums/Players.js +0 -11
- package/js/enums/StreamTypes.js +0 -15
- package/js/utils/EventsCall.js +0 -22
- package/js/utils/HttpCall.js +0 -57
- package/js/utils/LicenseCall.js +0 -18
- package/js/utils/Logger.js +0 -40
- package/js/utils/PlayerDetector.js +0 -75
- package/js/utils/PlayerInitCall.js +0 -22
- package/js/utils/SessionCreationCall.js +0 -22
- package/js/utils/Settings.js +0 -3
- package/js/utils/Utils.js +0 -195
- package/precommit.bash +0 -8
- package/tests/stage1.test.js +0 -50
- package/webpack.config.debug.js +0 -34
- package/webpack.config.js +0 -40
- package/webpack.config.release.js +0 -62
|
@@ -1,503 +0,0 @@
|
|
|
1
|
-
import logger from '../utils/Logger';
|
|
2
|
-
import StateMachine from 'javascript-state-machine';
|
|
3
|
-
import Events from '../enums/Events';
|
|
4
|
-
import {HEARTBEAT_THRESHOLD} from '../utils/Settings';
|
|
5
|
-
import {Players} from '../enums/Players';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export class VideojsAnalyticsStateMachine {
|
|
9
|
-
static PAUSE_SEEK_DELAY = 200;
|
|
10
|
-
static SEEKED_PAUSE_DELAY = 300;
|
|
11
|
-
|
|
12
|
-
constructor(stateMachineCallbacks, opts = {}) {
|
|
13
|
-
this.stateMachineCallbacks = stateMachineCallbacks;
|
|
14
|
-
|
|
15
|
-
this.pausedTimestamp = null;
|
|
16
|
-
this.seekTimestamp = 0;
|
|
17
|
-
this.seekedTimestamp = 0;
|
|
18
|
-
this.seekedTimeout = 0;
|
|
19
|
-
this.onEnterStateTimestamp = 0;
|
|
20
|
-
this.lastPlayHeadDuration = 0;
|
|
21
|
-
this.autoPlay = false;
|
|
22
|
-
|
|
23
|
-
this.States = {
|
|
24
|
-
SETUP : 'SETUP',
|
|
25
|
-
STARTUP : 'STARTUP',
|
|
26
|
-
READY : 'READY',
|
|
27
|
-
PLAYING : 'PLAYING',
|
|
28
|
-
REBUFFERING : 'REBUFFERING',
|
|
29
|
-
PAUSE : 'PAUSE',
|
|
30
|
-
QUALITYCHANGE : 'QUALITYCHANGE',
|
|
31
|
-
PAUSED_SEEKING : 'PAUSED_SEEKING',
|
|
32
|
-
PLAY_SEEKING : 'PLAY_SEEKING',
|
|
33
|
-
END_PLAY_SEEKING : 'END_PLAY_SEEKING',
|
|
34
|
-
QUALITYCHANGE_PAUSE : 'QUALITYCHANGE_PAUSE',
|
|
35
|
-
QUALITYCHANGE_REBUFFERING: 'QUALITYCHANGE_REBUFFERING',
|
|
36
|
-
END : 'END',
|
|
37
|
-
ERROR : 'ERROR',
|
|
38
|
-
MUTING_READY : 'MUTING_READY',
|
|
39
|
-
MUTING_PLAY : 'MUTING_PLAY',
|
|
40
|
-
MUTING_PAUSE : 'MUTING_PAUSE',
|
|
41
|
-
CASTING : 'CASTING'
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
this.createStateMachine(opts);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
getAllStates() {
|
|
48
|
-
return [
|
|
49
|
-
...Object.keys(this.States).map(key => this.States[key]),
|
|
50
|
-
'FINISH_PLAY_SEEKING',
|
|
51
|
-
'PLAY_SEEK',
|
|
52
|
-
'FINISH_QUALITYCHANGE_PAUSE',
|
|
53
|
-
'FINISH_QUALITYCHANGE',
|
|
54
|
-
'FINISH_QUALITYCHANGE_REBUFFERING'];
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
createStateMachine(opts = {}) {
|
|
58
|
-
this.stateMachine = StateMachine.create({
|
|
59
|
-
initial : this.States.SETUP,
|
|
60
|
-
error: (eventName, from, to, args, errorCode, errorMessage) => {
|
|
61
|
-
logger.error('Error in statemachine: ' + errorMessage);
|
|
62
|
-
},
|
|
63
|
-
events : [
|
|
64
|
-
{name: Events.TIMECHANGED, from: this.States.SETUP, to: this.States.SETUP},
|
|
65
|
-
{name: Events.READY, from: [this.States.SETUP, this.States.ERROR], to: this.States.READY},
|
|
66
|
-
{name: Events.PLAY, from: this.States.READY, to: this.States.STARTUP},
|
|
67
|
-
// For autoplay
|
|
68
|
-
{name: Events.PLAY, from: this.States.SETUP, to: this.States.SETUP},
|
|
69
|
-
{name: Events.TIMECHANGED, from: this.States.READY, to: this.States.STARTUP},
|
|
70
|
-
|
|
71
|
-
{name: Events.START_BUFFERING, from: this.States.STARTUP, to: this.States.STARTUP},
|
|
72
|
-
{name: Events.END_BUFFERING, from: this.States.STARTUP, to: this.States.STARTUP},
|
|
73
|
-
{name: Events.VIDEO_CHANGE, from: this.States.STARTUP, to: this.States.STARTUP},
|
|
74
|
-
{name: Events.AUDIO_CHANGE, from: this.States.STARTUP, to: this.States.STARTUP},
|
|
75
|
-
{name: Events.TIMECHANGED, from: this.States.STARTUP, to: this.States.PLAYING},
|
|
76
|
-
|
|
77
|
-
{name: Events.TIMECHANGED, from: this.States.PLAYING, to: this.States.PLAYING},
|
|
78
|
-
{name: Events.END_BUFFERING, from: this.States.PLAYING, to: this.States.PLAYING},
|
|
79
|
-
{name: Events.START_BUFFERING, from: this.States.PLAYING, to: this.States.REBUFFERING},
|
|
80
|
-
{name: Events.START_BUFFERING, from: this.States.REBUFFERING, to: this.States.REBUFFERING},
|
|
81
|
-
{name: Events.TIMECHANGED, from: this.States.REBUFFERING, to: this.States.PLAYING},
|
|
82
|
-
|
|
83
|
-
// Ignoring since it's pushed in a live stream
|
|
84
|
-
{name: Events.SEEK, from: this.States.STARTUP, to: this.States.STARTUP},
|
|
85
|
-
{name: Events.SEEK, from: this.States.PLAYING, to: this.States.PLAY_SEEKING },
|
|
86
|
-
{name: Events.TIMECHANGED, from: this.States.PLAY_SEEKING, to: this.States.PLAY_SEEKING },
|
|
87
|
-
{name: Events.TIMECHANGED, from: this.States.PAUSED_SEEKING, to: this.States.PAUSED_SEEKING },
|
|
88
|
-
|
|
89
|
-
{name: Events.PAUSE, from: this.States.PLAYING, to: this.States.PAUSE},
|
|
90
|
-
{name: Events.PAUSE, from: this.States.REBUFFERING, to: this.States.PAUSE},
|
|
91
|
-
{name: Events.TIMECHANGED, from: this.States.PAUSE, to: this.States.PAUSE},
|
|
92
|
-
{name: Events.PLAY, from: this.States.PAUSE, to: this.States.PLAYING},
|
|
93
|
-
|
|
94
|
-
{name: Events.VIDEO_CHANGE, from: this.States.PLAYING, to: this.States.QUALITYCHANGE},
|
|
95
|
-
{name: Events.AUDIO_CHANGE, from: this.States.PLAYING, to: this.States.QUALITYCHANGE},
|
|
96
|
-
{name: Events.VIDEO_CHANGE, from: this.States.QUALITYCHANGE, to: this.States.QUALITYCHANGE},
|
|
97
|
-
{name: Events.AUDIO_CHANGE, from: this.States.QUALITYCHANGE, to: this.States.QUALITYCHANGE},
|
|
98
|
-
{name: 'FINISH_QUALITYCHANGE', from: this.States.QUALITYCHANGE, to: this.States.PLAYING},
|
|
99
|
-
|
|
100
|
-
{name: Events.VIDEO_CHANGE, from: this.States.PAUSE, to: this.States.QUALITYCHANGE_PAUSE},
|
|
101
|
-
{name: Events.AUDIO_CHANGE, from: this.States.PAUSE, to: this.States.QUALITYCHANGE_PAUSE},
|
|
102
|
-
{
|
|
103
|
-
name: Events.VIDEO_CHANGE,
|
|
104
|
-
from: this.States.QUALITYCHANGE_PAUSE,
|
|
105
|
-
to : this.States.QUALITYCHANGE_PAUSE
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
name: Events.AUDIO_CHANGE,
|
|
109
|
-
from: this.States.QUALITYCHANGE_PAUSE,
|
|
110
|
-
to : this.States.QUALITYCHANGE_PAUSE
|
|
111
|
-
},
|
|
112
|
-
{name: 'FINISH_QUALITYCHANGE_PAUSE', from: this.States.QUALITYCHANGE_PAUSE, to: this.States.PAUSE},
|
|
113
|
-
|
|
114
|
-
{name: Events.SEEK, from: this.States.PAUSE, to: this.States.PAUSED_SEEKING},
|
|
115
|
-
{name: Events.SEEK, from: this.States.PAUSED_SEEKING, to: this.States.PAUSED_SEEKING},
|
|
116
|
-
{name: Events.AUDIO_CHANGE, from: this.States.PAUSED_SEEKING, to: this.States.PAUSED_SEEKING},
|
|
117
|
-
{name: Events.VIDEO_CHANGE, from: this.States.PAUSED_SEEKING, to: this.States.PAUSED_SEEKING},
|
|
118
|
-
{name: Events.START_BUFFERING, from: this.States.PAUSED_SEEKING, to: this.States.PAUSED_SEEKING},
|
|
119
|
-
{name: Events.END_BUFFERING, from: this.States.PAUSED_SEEKING, to: this.States.PAUSED_SEEKING},
|
|
120
|
-
{name: Events.SEEKED, from: this.States.PAUSED_SEEKING, to: this.States.PAUSE},
|
|
121
|
-
{name: Events.PLAY, from: this.States.PAUSED_SEEKING, to: this.States.PLAYING},
|
|
122
|
-
{name: Events.PAUSE, from: this.States.PAUSED_SEEKING, to: this.States.PAUSE},
|
|
123
|
-
|
|
124
|
-
{name: 'PLAY_SEEK', from: this.States.PAUSE, to: this.States.PLAY_SEEKING},
|
|
125
|
-
{name: 'PLAY_SEEK', from: this.States.PAUSED_SEEKING, to: this.States.PLAY_SEEKING},
|
|
126
|
-
{name: 'PLAY_SEEK', from: this.States.PLAY_SEEKING, to: this.States.PLAY_SEEKING},
|
|
127
|
-
{name: Events.SEEK, from: this.States.PLAY_SEEKING, to: this.States.PLAY_SEEKING},
|
|
128
|
-
{name: Events.AUDIO_CHANGE, from: this.States.PLAY_SEEKING, to: this.States.PLAY_SEEKING},
|
|
129
|
-
{name: Events.VIDEO_CHANGE, from: this.States.PLAY_SEEKING, to: this.States.PLAY_SEEKING},
|
|
130
|
-
{name: Events.START_BUFFERING, from: this.States.PLAY_SEEKING, to: this.States.PLAY_SEEKING},
|
|
131
|
-
{name: Events.END_BUFFERING, from: this.States.PLAY_SEEKING, to: this.States.PLAY_SEEKING},
|
|
132
|
-
{name: Events.SEEKED, from: this.States.PLAY_SEEKING, to: this.States.PLAY_SEEKING},
|
|
133
|
-
// {name: Events.PAUSE, from: this.States.PLAY_SEEKING, to: this.States.PLAY_SEEKING},
|
|
134
|
-
|
|
135
|
-
// We are ending the seek
|
|
136
|
-
{name: Events.SEEKED, from: this.States.PLAY_SEEKING, to: this.States.END_PLAY_SEEKING},
|
|
137
|
-
// {name: Events.PLAY, from: this.States.PLAY_SEEKING, to: this.States.END_PLAY_SEEKING},
|
|
138
|
-
|
|
139
|
-
{name: Events.START_BUFFERING, from: this.States.END_PLAY_SEEKING, to: this.States.END_PLAY_SEEKING},
|
|
140
|
-
{name: Events.END_BUFFERING, from: this.States.END_PLAY_SEEKING, to: this.States.END_PLAY_SEEKING},
|
|
141
|
-
{name: Events.SEEKED, from: this.States.END_PLAY_SEEKING, to: this.States.END_PLAY_SEEKING},
|
|
142
|
-
{name: Events.TIMECHANGED, from: this.States.END_PLAY_SEEKING, to: this.States.PLAYING},
|
|
143
|
-
|
|
144
|
-
{name: Events.END, from: this.States.PLAY_SEEKING, to: this.States.END},
|
|
145
|
-
{name: Events.END, from: this.States.PAUSED_SEEKING, to: this.States.END},
|
|
146
|
-
{name: Events.END, from: this.States.PLAYING, to: this.States.END},
|
|
147
|
-
{name: Events.END, from: this.States.PAUSE, to: this.States.END},
|
|
148
|
-
{name: Events.SEEK, from: this.States.END, to: this.States.END},
|
|
149
|
-
{name: Events.SEEKED, from: this.States.END, to: this.States.END},
|
|
150
|
-
{name: Events.TIMECHANGED, from: this.States.END, to: this.States.END},
|
|
151
|
-
{name: Events.END_BUFFERING, from: this.States.END, to: this.States.END},
|
|
152
|
-
{name: Events.START_BUFFERING, from: this.States.END, to: this.States.END},
|
|
153
|
-
{name: Events.END, from: this.States.END, to: this.States.END},
|
|
154
|
-
|
|
155
|
-
//Ignored - Livestreams do a Seek during startup and SEEKED once playback started
|
|
156
|
-
{name: Events.SEEKED, from: this.States.PLAYING, to: this.States.PLAYING},
|
|
157
|
-
|
|
158
|
-
{name: Events.PLAY, from: this.States.END, to: this.States.PLAYING},
|
|
159
|
-
|
|
160
|
-
{name: Events.ERROR, from: this.getAllStates(), to: this.States.ERROR},
|
|
161
|
-
{name: Events.PAUSE, from: this.States.ERROR, to: this.States.ERROR},
|
|
162
|
-
|
|
163
|
-
{name: Events.SEEK, from: this.States.END_PLAY_SEEKING, to: this.States.PLAY_SEEKING},
|
|
164
|
-
{name: 'FINISH_PLAY_SEEKING', from: this.States.END_PLAY_SEEKING, to: this.States.PLAYING},
|
|
165
|
-
|
|
166
|
-
{name: Events.UNLOAD, from: this.getAllStates(), to: this.States.END},
|
|
167
|
-
|
|
168
|
-
{name: Events.START_AD, from: this.States.PLAYING, to: this.States.AD},
|
|
169
|
-
{name: Events.END_AD, from: this.States.AD, to: this.States.PLAYING},
|
|
170
|
-
|
|
171
|
-
{name: Events.MUTE, from: this.States.READY, to: this.States.MUTING_READY},
|
|
172
|
-
{name: Events.UN_MUTE, from: this.States.READY, to: this.States.MUTING_READY},
|
|
173
|
-
{name: 'FINISH_MUTING', from: this.States.MUTING_READY, to: this.States.READY},
|
|
174
|
-
|
|
175
|
-
{name: Events.MUTE, from: this.States.PLAYING, to: this.States.MUTING_PLAY},
|
|
176
|
-
{name: Events.UN_MUTE, from: this.States.PLAYING, to: this.States.MUTING_PLAY},
|
|
177
|
-
{name: 'FINISH_MUTING', from: this.States.MUTING_PLAY, to: this.States.PLAYING},
|
|
178
|
-
|
|
179
|
-
{name: Events.MUTE, from: this.States.PAUSE, to: this.States.MUTING_PAUSE},
|
|
180
|
-
{name: Events.UN_MUTE, from: this.States.PAUSE, to: this.States.MUTING_PAUSE},
|
|
181
|
-
{name: 'FINISH_MUTING', from: this.States.MUTING_PAUSE, to: this.States.PAUSE},
|
|
182
|
-
|
|
183
|
-
{name: Events.START_CAST, from: [this.States.READY, this.States.PAUSE], to: this.States.CASTING},
|
|
184
|
-
{name: Events.PAUSE, from: this.States.CASTING, to: this.States.CASTING},
|
|
185
|
-
{name: Events.PLAY, from: this.States.CASTING, to: this.States.CASTING},
|
|
186
|
-
{name: Events.TIMECHANGED, from: this.States.CASTING, to: this.States.CASTING},
|
|
187
|
-
{name: Events.MUTE, from: this.States.CASTING, to: this.States.CASTING},
|
|
188
|
-
{name: Events.SEEK, from: this.States.CASTING, to: this.States.CASTING},
|
|
189
|
-
{name: Events.SEEKED, from: this.States.CASTING, to: this.States.CASTING},
|
|
190
|
-
{name: Events.END_CAST, from: this.States.CASTING, to: this.States.READY},
|
|
191
|
-
|
|
192
|
-
{name: Events.SEEK, from: this.States.READY, to: this.States.READY},
|
|
193
|
-
{name: Events.SEEKED, from: this.States.READY, to: this.States.READY},
|
|
194
|
-
{name: Events.SEEKED, from: this.States.STARTUP, to: this.States.STARTUP},
|
|
195
|
-
|
|
196
|
-
{name: Events.SOURCE_LOADED, from: this.getAllStates(), to: this.States.SETUP},
|
|
197
|
-
|
|
198
|
-
{name: Events.SOURCE_LOADED, from: this.States.SETUP, to: this.States.SETUP},
|
|
199
|
-
{name: Events.SOURCE_LOADED, from: this.States.READY, to: this.States.READY},
|
|
200
|
-
|
|
201
|
-
{name: Events.VIDEO_CHANGE, from: this.States.REBUFFERING, to: this.States.QUALITYCHANGE_REBUFFERING},
|
|
202
|
-
{name: Events.AUDIO_CHANGE, from: this.States.REBUFFERING, to: this.States.QUALITYCHANGE_REBUFFERING},
|
|
203
|
-
{name: Events.VIDEO_CHANGE, from: this.States.QUALITYCHANGE_REBUFFERING, to: this.States.QUALITYCHANGE_REBUFFERING},
|
|
204
|
-
{name: Events.AUDIO_CHANGE, from: this.States.QUALITYCHANGE_REBUFFERING, to: this.States.QUALITYCHANGE_REBUFFERING},
|
|
205
|
-
{name: 'FINISH_QUALITYCHANGE_REBUFFERING', from: this.States.QUALITYCHANGE_REBUFFERING, to: this.States.REBUFFERING},
|
|
206
|
-
],
|
|
207
|
-
callbacks: {
|
|
208
|
-
onpause : (event, from, to, timestamp) => {
|
|
209
|
-
if (from === this.States.PLAYING) {
|
|
210
|
-
this.pausedTimestamp = timestamp;
|
|
211
|
-
}
|
|
212
|
-
},
|
|
213
|
-
onbeforeevent: (event, from, to, timestamp, eventObject) => {
|
|
214
|
-
if (event === Events.PLAY && from === this.States.SETUP && to === this.States.SETUP) {
|
|
215
|
-
this.autoPlay = true;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
if (event === Events.SEEK && (from === this.States.PAUSE || from === this.States.PLAYING)) {
|
|
219
|
-
this.seekedFrom = this.lastPlayHeadDuration;
|
|
220
|
-
this.seekTimestamp = timestamp;
|
|
221
|
-
if (timestamp - this.pausedTimestamp < VideojsAnalyticsStateMachine.PAUSE_SEEK_DELAY) {
|
|
222
|
-
this.stateMachine.PLAY_SEEK(timestamp);
|
|
223
|
-
return false;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
if (event === Events.SEEK) {
|
|
228
|
-
clearTimeout(this.seekedTimeout);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
if (event === Events.SOURCE_LOADED) {
|
|
236
|
-
// event = sourceLoaded
|
|
237
|
-
// from = Ready/Setup
|
|
238
|
-
// to = Ready/Setup i.e. current event
|
|
239
|
-
// timestamp is current Timestamp
|
|
240
|
-
// eventObject = {} event obbject is there
|
|
241
|
-
|
|
242
|
-
this.stateMachineCallbacks.loaded(timestamp, this.States.READY, eventObject);
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
if ((event === Events.SEEKED && from === this.States.PAUSED_SEEKING)) {
|
|
247
|
-
this.seekedTimestamp = timestamp;
|
|
248
|
-
this.seekedTimeout = setTimeout(() => {
|
|
249
|
-
this.stateMachine.pause(timestamp, eventObject);
|
|
250
|
-
}, VideojsAnalyticsStateMachine.SEEKED_PAUSE_DELAY);
|
|
251
|
-
return false;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
if (from === this.States.REBUFFERING && to === this.States.QUALITYCHANGE_REBUFFERING) {
|
|
255
|
-
return false;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
if (eventObject) {
|
|
259
|
-
this.lastPlayHeadDuration = eventObject.currentTime*1000;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
},
|
|
263
|
-
onenterstate : (event, from, to, timestamp, eventObject) => {
|
|
264
|
-
if (to === this.States.SETUP) {
|
|
265
|
-
// event = startup
|
|
266
|
-
// from = none as it is the initial/first event
|
|
267
|
-
// to = SETUP
|
|
268
|
-
// timestamp is undefined
|
|
269
|
-
// eventObject is undefined
|
|
270
|
-
this.stateMachineCallbacks.setup(timestamp, this.States.SETUP, eventObject);
|
|
271
|
-
}
|
|
272
|
-
else if (to === this.States.READY) {
|
|
273
|
-
// event = ready
|
|
274
|
-
// from = SETUP
|
|
275
|
-
// to = Ready i.e. current event
|
|
276
|
-
// timestamp is current Timestamp
|
|
277
|
-
// eventObject = {} event obbject is there
|
|
278
|
-
eventObject.playerSoftware = Players.VIDEOJS;
|
|
279
|
-
this.stateMachineCallbacks.ready(timestamp, this.States.READY, eventObject);
|
|
280
|
-
}
|
|
281
|
-
else if (event === "play" && to === this.States.STARTUP) {
|
|
282
|
-
// Video is played for the first time after player iinitialisation
|
|
283
|
-
|
|
284
|
-
// event = play
|
|
285
|
-
// from = READY
|
|
286
|
-
// to = STARTUP i.e. current event
|
|
287
|
-
// timestamp is current Timestamp
|
|
288
|
-
// eventObject = {} event obbject is there
|
|
289
|
-
this.stateMachineCallbacks.first_play(timestamp, this.States.PLAY, eventObject);
|
|
290
|
-
}
|
|
291
|
-
else if (event === "timechanged" && from === this.States.STARTUP && to === this.States.PLAYING && this.autoPlay) {
|
|
292
|
-
// Video has started playing for the first time after player initialisation
|
|
293
|
-
|
|
294
|
-
// event = timechanged
|
|
295
|
-
// from = STARTUP
|
|
296
|
-
// to = PLAYING i.e. current event
|
|
297
|
-
// timestamp is current Timestamp
|
|
298
|
-
// eventObject = {} event obbject is there
|
|
299
|
-
this.stateMachineCallbacks.first_play(timestamp, this.States.PLAY, eventObject);
|
|
300
|
-
this.stateMachineCallbacks.playing(timestamp, this.States.PLAYING, eventObject);
|
|
301
|
-
this.stateMachineCallbacks.playback_started(eventObject);
|
|
302
|
-
}
|
|
303
|
-
else if (event === "play" && from === this.States.PAUSE) {
|
|
304
|
-
// Video is played after being paused
|
|
305
|
-
|
|
306
|
-
// event = play
|
|
307
|
-
// from = PAUSE
|
|
308
|
-
// to = PLAYING i.e. current event
|
|
309
|
-
// timestamp is current Timestamp
|
|
310
|
-
// eventObject = {} event obbject is there
|
|
311
|
-
this.stateMachineCallbacks.play(timestamp, this.States.PLAY, eventObject);
|
|
312
|
-
this.stateMachineCallbacks.playing(timestamp, this.States.PLAYING, eventObject);
|
|
313
|
-
}
|
|
314
|
-
else if (event === "timechanged" && from === this.States.STARTUP && to === this.States.PLAYING && !this.autoPlay) {
|
|
315
|
-
// Video has started playing for the first time after player initialisation
|
|
316
|
-
|
|
317
|
-
// event = timechanged
|
|
318
|
-
// from = STARTUP
|
|
319
|
-
// to = PLAYING i.e. current event
|
|
320
|
-
// timestamp is current Timestamp
|
|
321
|
-
// eventObject = {} event obbject is there
|
|
322
|
-
this.stateMachineCallbacks.playing(timestamp, this.States.PLAYING, eventObject);
|
|
323
|
-
this.stateMachineCallbacks.playback_started(eventObject);
|
|
324
|
-
}
|
|
325
|
-
else if (to === this.States.PAUSE && from === this.States.PLAYING) {
|
|
326
|
-
// Only fire pause event if the the video was playing
|
|
327
|
-
|
|
328
|
-
// event = pause
|
|
329
|
-
// from = PLAYING
|
|
330
|
-
// to = PAUSE i.e. current event
|
|
331
|
-
// timestamp is current Timestamp
|
|
332
|
-
// eventObject = {} event obbject is there
|
|
333
|
-
this.stateMachineCallbacks.pause(timestamp, this.States.PAUSE, eventObject);
|
|
334
|
-
}
|
|
335
|
-
else if (to === this.States.END) {
|
|
336
|
-
// event = end
|
|
337
|
-
// from = PLAYING
|
|
338
|
-
// to = END i.e. current event
|
|
339
|
-
// timestamp is current Timestamp
|
|
340
|
-
// eventObject = {} event obbject is there
|
|
341
|
-
|
|
342
|
-
this.stateMachineCallbacks.end(timestamp, this.States.END, eventObject);
|
|
343
|
-
}
|
|
344
|
-
else if (to === this.States.END) {
|
|
345
|
-
// event = mute
|
|
346
|
-
// from = PLAYING/PAUSE etc
|
|
347
|
-
// to = MUTING_PAUSE/etc i.e. current event
|
|
348
|
-
// timestamp is current Timestamp
|
|
349
|
-
// eventObject = {} event obbject is there
|
|
350
|
-
|
|
351
|
-
this.stateMachineCallbacks.mute(timestamp, eventObject);
|
|
352
|
-
}
|
|
353
|
-
else if (event === Events.START_BUFFERING) {
|
|
354
|
-
// event = startBuffering
|
|
355
|
-
// from = PLAYING etc
|
|
356
|
-
// to = REBUFFERING/etc i.e. current event
|
|
357
|
-
// timestamp is current Timestamp
|
|
358
|
-
// eventObject = {} event obbject is there
|
|
359
|
-
|
|
360
|
-
this.stateMachineCallbacks.start_rebuffer(timestamp, this.States.REBUFFERING, eventObject);
|
|
361
|
-
}
|
|
362
|
-
else if (event === "timechanged" && from === this.States.REBUFFERING && to === this.States.PLAYING) {
|
|
363
|
-
// event = endBuffering
|
|
364
|
-
// from = REBUFFERING
|
|
365
|
-
// to = PLAYING/etc i.e. current event
|
|
366
|
-
// timestamp is current Timestamp
|
|
367
|
-
// eventObject = {} event obbject is there
|
|
368
|
-
|
|
369
|
-
this.stateMachineCallbacks.end_rebuffer(timestamp, this.States.REBUFFERING, eventObject);
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
if (from === 'none' && opts.starttime) {
|
|
374
|
-
this.onEnterStateTimestamp = opts.starttime;
|
|
375
|
-
} else {
|
|
376
|
-
this.onEnterStateTimestamp = timestamp || new Date().getTime();
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
// logger.log('[' + from + '] => ' + event + ' => [' + to + ']');
|
|
380
|
-
//logger.log('Entering State ' + to + ' with ' + event + ' from ' + from);
|
|
381
|
-
if (eventObject && to !== this.States.PAUSED_SEEKING && to !== this.States.PLAY_SEEKING && to !== this.States.END_PLAY_SEEKING) {
|
|
382
|
-
//logger.log('Setting video time start to ' + eventObject.currentTime + ', going to ' + to);
|
|
383
|
-
this.stateMachineCallbacks.setVideoTimeStartFromEvent(eventObject);
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
if (event === 'PLAY_SEEK' && to === this.States.PLAY_SEEKING && to !== this.States.PLAY_SEEKING && to !== this.States.END_PLAY_SEEKING) {
|
|
387
|
-
this.seekTimestamp = this.onEnterStateTimestamp;
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
// if (event === Events.START_CAST && to === this.States.CASTING) {
|
|
391
|
-
// this.stateMachineCallbacks.startCasting(timestamp, eventObject);
|
|
392
|
-
// }
|
|
393
|
-
},
|
|
394
|
-
onafterevent : (event, from, to, timestamp) => {
|
|
395
|
-
if (to === this.States.QUALITYCHANGE) {
|
|
396
|
-
this.stateMachine.FINISH_QUALITYCHANGE(timestamp);
|
|
397
|
-
}
|
|
398
|
-
if (to === this.States.MUTING_READY || to === this.States.MUTING_PLAY || to === this.States.MUTING_PAUSE) {
|
|
399
|
-
this.stateMachine.FINISH_MUTING(timestamp);
|
|
400
|
-
}
|
|
401
|
-
},
|
|
402
|
-
onleavestate : (event, from, to, timestamp, eventObject) => {
|
|
403
|
-
this.stateMachineCallbacks.resetSessionExpiry();
|
|
404
|
-
|
|
405
|
-
if (!timestamp) {
|
|
406
|
-
return;
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
const stateDuration = timestamp - this.onEnterStateTimestamp;
|
|
410
|
-
//logger.log('State ' + from + ' was ' + stateDuration + ' ms event:' + event);
|
|
411
|
-
|
|
412
|
-
if (eventObject && to !== this.States.PAUSED_SEEKING && to !== this.States.PLAY_SEEKING && to !== this.States.END_PLAY_SEEKING) {
|
|
413
|
-
logger.log('Setting video time end to ' + eventObject.currentTime + ', going to ' + to);
|
|
414
|
-
this.stateMachineCallbacks.setVideoTimeEndFromEvent(eventObject);
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
if (event === 'PLAY_SEEK' && from === this.States.PAUSE) {
|
|
418
|
-
return true;
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
// Similar to bitmovin, copy the logic
|
|
422
|
-
const fnName = from.toLowerCase();
|
|
423
|
-
if (from === this.States.END_PLAY_SEEKING || from === this.States.PAUSED_SEEKING) {
|
|
424
|
-
const seekDuration = this.seekedTimestamp - this.seekTimestamp;
|
|
425
|
-
this.stateMachineCallbacks.playback_seeked(this.seekedFrom, eventObject.currentTime*1000, seekDuration, to);
|
|
426
|
-
logger.log('Seek was ' + seekDuration + 'ms');
|
|
427
|
-
} else if (event === Events.UNLOAD && from === this.States.PLAYING) {
|
|
428
|
-
this.stateMachineCallbacks.playingAndBye(stateDuration, fnName, eventObject);
|
|
429
|
-
} else if (from === this.States.PAUSE && to !== this.States.PAUSED_SEEKING) {
|
|
430
|
-
this.stateMachineCallbacks.setVideoTimeStartFromEvent(event);
|
|
431
|
-
// this.stateMachineCallbacks.pause(stateDuration, fnName, eventObject);
|
|
432
|
-
} else {
|
|
433
|
-
// const callbackFunction = this.stateMachineCallbacks[fnName];
|
|
434
|
-
// if (typeof callbackFunction === 'function') {
|
|
435
|
-
// callbackFunction(stateDuration, fnName, eventObject);
|
|
436
|
-
// } else {
|
|
437
|
-
// logger.error('Could not find callback function for ' + fnName);
|
|
438
|
-
// }
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
// if (eventObject && to !== this.States.PAUSED_SEEKING && to !== this.States.PLAY_SEEKING && to !== this.States.END_PLAY_SEEKING) {
|
|
442
|
-
// //logger.log('Setting video time start to ' + eventObject.currentTime + ', going to ' + to);
|
|
443
|
-
// this.stateMachineCallbacks.setVideoTimeStartFromEvent(eventObject);
|
|
444
|
-
// }
|
|
445
|
-
|
|
446
|
-
if (event === Events.VIDEO_CHANGE) {
|
|
447
|
-
this.stateMachineCallbacks.videoChange(eventObject);
|
|
448
|
-
} else if (event === Events.AUDIO_CHANGE) {
|
|
449
|
-
this.stateMachineCallbacks.audioChange(eventObject);
|
|
450
|
-
} else if (event === Events.MUTE) {
|
|
451
|
-
logger.log('Setting sample to muted');
|
|
452
|
-
this.stateMachineCallbacks.mute();
|
|
453
|
-
} else if (event === Events.UN_MUTE) {
|
|
454
|
-
logger.log('Setting sample to unmuted');
|
|
455
|
-
this.stateMachineCallbacks.unMute();
|
|
456
|
-
}
|
|
457
|
-
},
|
|
458
|
-
onseek : (event, from, to, timestamp) => {
|
|
459
|
-
this.seekTimestamp = timestamp;
|
|
460
|
-
},
|
|
461
|
-
onseeked : (event, from, to, timestamp) => {
|
|
462
|
-
this.seekedTimestamp = timestamp;
|
|
463
|
-
},
|
|
464
|
-
ontimechanged: (event, from, to, timestamp, eventObject) => {
|
|
465
|
-
const stateDuration = timestamp - this.onEnterStateTimestamp;
|
|
466
|
-
|
|
467
|
-
if (stateDuration > HEARTBEAT_THRESHOLD) {
|
|
468
|
-
this.stateMachineCallbacks.setVideoTimeEndFromEvent(eventObject);
|
|
469
|
-
|
|
470
|
-
logger.log('Sending heartbeat');
|
|
471
|
-
this.stateMachineCallbacks.heartbeat(stateDuration, from.toLowerCase(), eventObject);
|
|
472
|
-
this.onEnterStateTimestamp = timestamp;
|
|
473
|
-
|
|
474
|
-
this.stateMachineCallbacks.setVideoTimeStartFromEvent(eventObject);
|
|
475
|
-
this.stateMachineCallbacks.resetSessionExpiry();
|
|
476
|
-
}
|
|
477
|
-
},
|
|
478
|
-
onplayerError: (event, from, to, timestamp, eventObject) => {
|
|
479
|
-
this.stateMachineCallbacks.error(eventObject);
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
});
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
callEvent(eventType, eventObject, timestamp) {
|
|
486
|
-
const exec = this.stateMachine[eventType];
|
|
487
|
-
|
|
488
|
-
if (exec) {
|
|
489
|
-
exec.call(this.stateMachine, timestamp, eventObject);
|
|
490
|
-
} else {
|
|
491
|
-
logger.log('Ignored Event: ' + eventType);
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
updateMetadata(metadata) {
|
|
496
|
-
this.stateMachineCallbacks.updateSample(metadata);
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
static pad(str, length) {
|
|
500
|
-
const padStr = new Array(length).join(' ');
|
|
501
|
-
return (str + padStr).slice(0, length);
|
|
502
|
-
}
|
|
503
|
-
}
|
package/js/cast/CastClient.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import {MESSAGE_NAMESPACE} from '../utils/Settings';
|
|
2
|
-
import logger from '../utils/Logger';
|
|
3
|
-
|
|
4
|
-
/* global cast */
|
|
5
|
-
|
|
6
|
-
class CastClient {
|
|
7
|
-
setUp() {
|
|
8
|
-
logger.log('setting up cast session');
|
|
9
|
-
this.castSession = cast.framework.CastContext.getInstance().getCurrentSession();
|
|
10
|
-
this.addMessageListener();
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
addMessageListener() {
|
|
14
|
-
const applicationMetadata = this.castSession.getApplicationMetadata();
|
|
15
|
-
if (!applicationMetadata || applicationMetadata.namespaces.indexOf(MESSAGE_NAMESPACE) < 0) {
|
|
16
|
-
logger.log('No analytics on chrome cast receiver enabled!');
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
logger.log('adding message listener');
|
|
21
|
-
this.castSession.addMessageListener(MESSAGE_NAMESPACE, (ns, message) => {
|
|
22
|
-
logger.log('Received: ' + ns + ' ' + message);
|
|
23
|
-
|
|
24
|
-
try {
|
|
25
|
-
const receiverMessage = JSON.parse(message);
|
|
26
|
-
this.handleReceiverMessage(receiverMessage);
|
|
27
|
-
|
|
28
|
-
} catch (error) {
|
|
29
|
-
logger.error('Message parsing failed ' + message);
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
handleReceiverMessage(message) {
|
|
35
|
-
logger.log(message);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
sendMessage(message) {
|
|
39
|
-
const applicationMetadata = this.castSession.getApplicationMetadata();
|
|
40
|
-
if (!applicationMetadata || applicationMetadata.namespaces.indexOf(MESSAGE_NAMESPACE) < 0) {
|
|
41
|
-
logger.log('No analytics on chrome cast receiver enabled!');
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
logger.log('Sending message: ' + JSON.stringify(message));
|
|
46
|
-
this.castSession.sendMessage(MESSAGE_NAMESPACE, message);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export default CastClient;
|
package/js/cast/CastReceiver.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import {MESSAGE_NAMESPACE} from '../utils/Settings';
|
|
2
|
-
import logger from '../utils/Logger';
|
|
3
|
-
|
|
4
|
-
/* global cast */
|
|
5
|
-
|
|
6
|
-
class CastReceiver {
|
|
7
|
-
setUp() {
|
|
8
|
-
const castReceiverManager = cast.receiver.CastReceiverManager.getInstance();
|
|
9
|
-
this.messageBus = castReceiverManager.getCastMessageBus(
|
|
10
|
-
MESSAGE_NAMESPACE,
|
|
11
|
-
cast.receiver.CastMessageBus.MessageType.JSON
|
|
12
|
-
);
|
|
13
|
-
|
|
14
|
-
logger.log(this.messageBus);
|
|
15
|
-
|
|
16
|
-
this.messageBus.onMessage = (message) => {
|
|
17
|
-
logger.log('Received message from cast client: ' + JSON.stringify(message));
|
|
18
|
-
|
|
19
|
-
const castClientMessage = message.data;
|
|
20
|
-
this.handleClientMessage(castClientMessage);
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
setCallback(callback) {
|
|
25
|
-
this.callback = callback;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
handleClientMessage(event) {
|
|
29
|
-
this.callback(event);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
sendMessage(message) {
|
|
33
|
-
this.messageBus.broadcast(message);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export default CastReceiver;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import PlayerDetector from '../utils/PlayerDetector';
|
|
2
|
-
|
|
3
|
-
import BitmovinAdapter from '../adapters/BitmovinAdapter';
|
|
4
|
-
import Bitmovin7Adapter from '../adapters/Bitmovin7Adapter';
|
|
5
|
-
import VideoJsAdapter from '../adapters/VideoJsAdapter';
|
|
6
|
-
|
|
7
|
-
import {HlsjsAdapter} from '../adapters/HlsjsAdapter';
|
|
8
|
-
import {ShakaAdapter} from '../adapters/ShakaAdapter';
|
|
9
|
-
import {DashjsAdapter} from '../adapters/DashjsAdapter';
|
|
10
|
-
import {HTML5Adapter} from '../adapters/HTML5Adapter';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Stateless. Auto-maps given player instance to new adapter instances.
|
|
14
|
-
* @class
|
|
15
|
-
*/
|
|
16
|
-
class AdapterFactory {
|
|
17
|
-
/**
|
|
18
|
-
* @param {object} player
|
|
19
|
-
* @param {AnalyticsEventCallback} eventCallback
|
|
20
|
-
* @param {AnalyticsStateMachine} stateMachine
|
|
21
|
-
*/
|
|
22
|
-
static getAdapter(player, eventCallback, stateMachine, mediaElement=null) {
|
|
23
|
-
if (PlayerDetector.isBitmovinVersionPre7(player)) {
|
|
24
|
-
return new BitmovinAdapter(player, eventCallback);
|
|
25
|
-
} else if (PlayerDetector.isBitmovinVersion7Plus(player)) {
|
|
26
|
-
return new Bitmovin7Adapter(player, eventCallback);
|
|
27
|
-
} else if (PlayerDetector.isVideoJs(player)) {
|
|
28
|
-
return new VideoJsAdapter(player, eventCallback, stateMachine);
|
|
29
|
-
} else if(PlayerDetector.isHlsjs(player)) {
|
|
30
|
-
return new HlsjsAdapter(player, eventCallback, stateMachine);
|
|
31
|
-
} else if(PlayerDetector.isShaka(player)) {
|
|
32
|
-
return new ShakaAdapter(player, eventCallback, stateMachine, mediaElement);
|
|
33
|
-
} else if (PlayerDetector.isDashjs(player)) {
|
|
34
|
-
return new DashjsAdapter(player, eventCallback, stateMachine);
|
|
35
|
-
}else{
|
|
36
|
-
return new HTML5Adapter(player, eventCallback, stateMachine)
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export default AdapterFactory;
|