1
1
import { Injectable , OnDestroy } from '@angular/core' ;
2
- import { BehaviorSubject } from 'rxjs' ;
2
+ import { asyncScheduler , BehaviorSubject , merge } from 'rxjs' ;
3
3
import { Observable , of as ObservableOf } from 'rxjs' ;
4
4
import { throwError } from 'rxjs' ;
5
- import { map , catchError } from 'rxjs/operators' ;
5
+ import { map , catchError , observeOn } from 'rxjs/operators' ;
6
6
import {
7
- KalturaClient ,
8
- KalturaMultiRequest ,
7
+ KalturaClient , KalturaLiveStreamConfiguration ,
8
+ KalturaMultiRequest , KalturaPlaybackProtocol ,
9
9
KalturaSipSourceType ,
10
10
PexipGenerateSipUrlAction
11
11
} from 'kaltura-ngx-client' ;
@@ -26,13 +26,14 @@ import {KalturaConversionProfileFilter} from 'kaltura-ngx-client';
26
26
import { KalturaFilterPager } from 'kaltura-ngx-client' ;
27
27
import { KalturaConversionProfileType } from 'kaltura-ngx-client' ;
28
28
import { KalturaNullableBoolean } from 'kaltura-ngx-client' ;
29
- import { AreaBlockerMessage } from '@kaltura-ng/kaltura-ui' ;
29
+ import { AreaBlockerMessage , KalturaValidators } from '@kaltura-ng/kaltura-ui' ;
30
30
import { BaseEntryGetAction } from 'kaltura-ngx-client' ;
31
31
import { KMCPermissions , KMCPermissionsService } from 'app-shared/kmc-shared/kmc-permissions' ;
32
32
import { ContentEntryViewSections } from 'app-shared/kmc-shared/kmc-views/details-views/content-entry-view.service' ;
33
33
import { LiveDashboardAppViewService } from 'app-shared/kmc-shared/kmc-views/component-views' ;
34
34
import { KalturaLogger } from '@kaltura-ng/kaltura-logger' ;
35
35
import { cancelOnDestroy , tag } from '@kaltura-ng/kaltura-common' ;
36
+ import { FormBuilder , FormGroup } from "@angular/forms" ;
36
37
37
38
export interface bitrate {
38
39
enabled : boolean ,
@@ -65,6 +66,7 @@ export class EntryLiveWidget extends EntryWidget implements OnDestroy {
65
66
public _manualStreamsConfiguration = [ ] ;
66
67
public _bitrates : bitrate [ ] = [ ] ;
67
68
public _availableBitrates = AVAIL_BITRATES ;
69
+ public _form : FormGroup ;
68
70
69
71
public _autoStartOptions = [
70
72
{ label : this . _appLocalization . get ( 'applications.content.entryDetails.live.disabled' ) , value : true } ,
@@ -77,10 +79,45 @@ export class EntryLiveWidget extends EntryWidget implements OnDestroy {
77
79
private _permissionsService : KMCPermissionsService ,
78
80
private _browserService : BrowserService ,
79
81
private _liveDasboardAppViewService : LiveDashboardAppViewService ,
82
+ private _fb : FormBuilder ,
80
83
logger : KalturaLogger ) {
81
84
super ( ContentEntryViewSections . Live , logger ) ;
82
85
}
83
86
87
+ public initManualForm ( ) {
88
+ this . _form = this . _fb . group ( {
89
+ flashHDSURL : [ '' , KalturaValidators . url ] ,
90
+ hlsStreamUrl : [ '' , KalturaValidators . url ] ,
91
+ dashStreamUrl : [ '' , KalturaValidators . url ]
92
+ } ,
93
+ {
94
+ validator : ( formGroup : FormGroup ) => {
95
+ return this . _atLeastOneUrlValidator ( formGroup ) ;
96
+ }
97
+ } ) ;
98
+
99
+ let flashHDSURL = this . _manualStreamsConfiguration . find ( stream => stream . label . split ( " " ) [ 0 ] === KalturaPlaybackProtocol . akamaiHds ) ?. url || '' ;
100
+ if ( flashHDSURL === '' ) {
101
+ flashHDSURL = this . _manualStreamsConfiguration . find ( stream => stream . label . split ( " " ) [ 0 ] === KalturaPlaybackProtocol . hds ) ?. url || '' ;
102
+ }
103
+ const hlsStreamUrl = this . _manualStreamsConfiguration . find ( stream => stream . label . split ( " " ) [ 0 ] === KalturaPlaybackProtocol . appleHttp ) ?. url || '' ;
104
+ const dashStreamUrl = this . _manualStreamsConfiguration . find ( stream => stream . label . split ( " " ) [ 0 ] === KalturaPlaybackProtocol . mpegDash ) ?. url || '' ;
105
+ this . _form . reset ( { flashHDSURL, hlsStreamUrl, dashStreamUrl } ) ;
106
+
107
+ merge ( this . _form . valueChanges ,
108
+ this . _form . statusChanges )
109
+ . pipe ( observeOn ( asyncScheduler ) ) // using async scheduler so the form group status/dirty mode will be synchornized
110
+ . pipe ( cancelOnDestroy ( this ) )
111
+ . subscribe (
112
+ ( ) => {
113
+ super . updateState ( {
114
+ isValid : this . _form . status !== 'INVALID' ,
115
+ isDirty : this . _form . dirty
116
+ } ) ;
117
+ }
118
+ ) ;
119
+ }
120
+
84
121
protected onReset ( ) {
85
122
this . _DVRStatus = "" ;
86
123
this . _manualLiveUrl = "" ;
@@ -118,8 +155,41 @@ export class EntryLiveWidget extends EntryWidget implements OnDestroy {
118
155
( data as KalturaLiveStreamEntry ) . conversionProfileId = this . _selectedConversionProfile ;
119
156
}
120
157
if ( this . _liveType === "manual" ) {
121
- const entry = this . data as KalturaLiveStreamEntry ;
122
- ( data as KalturaLiveStreamEntry ) . hlsStreamUrl = this . _manualLiveUrl ;
158
+ const entry = data as KalturaLiveStreamEntry ;
159
+ entry . liveStreamConfigurations = [ ] ;
160
+ // save hls stream to main entry and stream configuration
161
+ const hlsStreamUrl = this . _form . controls [ 'hlsStreamUrl' ] . value ;
162
+ entry . hlsStreamUrl = hlsStreamUrl ;
163
+ if ( hlsStreamUrl && hlsStreamUrl . length ) {
164
+ const cfg = new KalturaLiveStreamConfiguration ( ) ;
165
+ cfg . protocol = KalturaPlaybackProtocol . appleHttp ;
166
+ cfg . url = hlsStreamUrl ;
167
+ entry . liveStreamConfigurations . push ( cfg ) ;
168
+ }
169
+
170
+ // save flash stream to stream configuration
171
+ const flashStreamUrl = this . _form . controls [ 'flashHDSURL' ] . value ;
172
+ if ( flashStreamUrl && flashStreamUrl . length ) {
173
+ let protocol = KalturaPlaybackProtocol . akamaiHds ;
174
+ let flashStreamConfig = ( this . data as KalturaLiveStreamEntry ) . liveStreamConfigurations . find ( cfg => cfg . protocol === KalturaPlaybackProtocol . akamaiHds ) ;
175
+ if ( ! flashStreamConfig ) {
176
+ protocol = KalturaPlaybackProtocol . hds ;
177
+ }
178
+ const cfg = new KalturaLiveStreamConfiguration ( ) ;
179
+ cfg . protocol = protocol ;
180
+ cfg . url = flashStreamUrl ;
181
+ entry . liveStreamConfigurations . push ( cfg ) ;
182
+ }
183
+
184
+ // save dash stream to stream configuration
185
+ const dashStreamUrl = this . _form . controls [ 'dashStreamUrl' ] . value ;
186
+ if ( dashStreamUrl && dashStreamUrl . length ) {
187
+ const dashStreamConfig = ( this . data as KalturaLiveStreamEntry ) . liveStreamConfigurations . find ( cfg => cfg . protocol === KalturaPlaybackProtocol . mpegDash ) ;
188
+ const cfg = new KalturaLiveStreamConfiguration ( ) ;
189
+ cfg . protocol = KalturaPlaybackProtocol . mpegDash ;
190
+ cfg . url = dashStreamUrl ;
191
+ entry . liveStreamConfigurations . push ( cfg ) ;
192
+ }
123
193
}
124
194
}
125
195
@@ -152,12 +222,34 @@ export class EntryLiveWidget extends EntryWidget implements OnDestroy {
152
222
153
223
protected onValidate ( wasActivated : boolean ) : Observable < { isValid : boolean } > {
154
224
return Observable . create ( observer => {
155
- const isValid = this . _liveType === "universal" ? this . _validateBitrates ( { updateDirtyMode : false } ) : true ;
156
- observer . next ( { isValid} ) ;
225
+ let isValid = this . _liveType === "universal" ? this . _validateBitrates ( { updateDirtyMode : false } ) : true ;
226
+ if ( this . _liveType === "manual" ) {
227
+ for ( const controlName in this . _form . controls ) {
228
+ if ( this . _form . controls . hasOwnProperty ( controlName ) ) {
229
+ if ( this . _form . get ( controlName ) . errors !== null ) {
230
+ isValid = false ;
231
+ }
232
+ }
233
+ }
234
+ if ( this . _form . errors !== null ) {
235
+ isValid = false ;
236
+ }
237
+ }
238
+ observer . next ( { isValid} ) ;
157
239
observer . complete ( )
158
240
} ) ;
159
241
}
160
242
243
+ private _atLeastOneUrlValidator ( formgroup : FormGroup ) {
244
+ if ( ! formgroup . controls [ 'flashHDSURL' ] . value &&
245
+ ! formgroup . controls [ 'hlsStreamUrl' ] . value &&
246
+ ! formgroup . controls [ 'dashStreamUrl' ] . value ) {
247
+ return { atLeastOneUrl : true } ;
248
+ } else {
249
+ return null ;
250
+ }
251
+ }
252
+
161
253
protected onActivate ( firstTimeActivating : boolean ) {
162
254
// set live type and load data accordingly
163
255
switch ( this . data . sourceType . toString ( ) ) {
@@ -228,6 +320,7 @@ export class EntryLiveWidget extends EntryWidget implements OnDestroy {
228
320
case KalturaSourceType . manualLiveStream . toString ( ) :
229
321
this . _liveType = "manual" ;
230
322
this . _setManualStreams ( ) ;
323
+ this . initManualForm ( ) ;
231
324
break ;
232
325
}
233
326
0 commit comments