@@ -656,6 +656,60 @@ const createClient = (profile, userAgent, opt = {}) => {
656
656
}
657
657
}
658
658
659
+ const subscribeToJourney = async ( userId , channelIds , journeyRefreshToken , todo ) => { // todo
660
+ if ( ! isNonEmptyString ( userId ) ) {
661
+ throw new TypeError ( 'userId must be a non-empty string' )
662
+ }
663
+ if ( ! Array . isArray ( channelIds ) || channelIds . length === 0 ) {
664
+ throw new TypeError ( 'channelIds must be a non-empty array' )
665
+ }
666
+ for ( let i = 0 ; i < channelIds . length ; i ++ ) {
667
+ if ( ! isNonEmptyString ( channelIds [ i ] ) ) {
668
+ throw new TypeError ( `channelIds[${ i } ] must be a non-empty string` )
669
+ }
670
+ }
671
+ if ( ! isNonEmptyString ( journeyRefreshToken ) ) {
672
+ throw new TypeError ( 'journeyRefreshToken must be a non-empty string' )
673
+ }
674
+
675
+ // todo: make customizable
676
+ const hysteresis = {
677
+ minDeviationInterval : 5 , // todo: what exactly is this?
678
+ notificationStart : 20 , // todo: what exactly is this?
679
+ }
680
+ const monitorFlags = [
681
+ // todo: what exactly are these?
682
+ 'OF' ,
683
+ 'PF' ,
684
+ 'DF' ,
685
+ 'AF' ,
686
+ 'DV' ,
687
+ 'FTF' ,
688
+ ]
689
+ const serviceDays = {
690
+ beginDate : '20191215' ,
691
+ endDate : '20211211' ,
692
+ selectedDays : '00011111001111100111110011111001111100111110011111001111100111110011111001111100111110011111001111100111110011111001111100111110011111001111100111110011111001111100111110011111001111100111110011111001111100111110011111001111100111110011111001111100111110011111001111100111110011111001111100111110011111001111100111110011111001111100111110011111001111100111110011110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' ,
693
+ }
694
+
695
+ const { res} = await profile . request ( { profile, opt} , userAgent , {
696
+ meth : 'SubscrCreate' ,
697
+ req : {
698
+ userId,
699
+ channels : channelIds . map ( ( channelId ) => ( { channelId} ) ) ,
700
+ conSubscr : {
701
+ ctxRecon : journeyRefreshToken ,
702
+ // todo: `data`?
703
+ hysteresis,
704
+ monitorFlags,
705
+ serviceDays,
706
+ } ,
707
+ } ,
708
+ } )
709
+ _checkSubscriptionsResultCode ( res )
710
+ return res . subscrId
711
+ }
712
+
659
713
const client = {
660
714
departures,
661
715
arrivals,
@@ -676,6 +730,7 @@ const createClient = (profile, userAgent, opt = {}) => {
676
730
client . createSubscriptionsUser = createSubscriptionsUser
677
731
client . subscriptions = subscriptions
678
732
client . subscription = subscription
733
+ client . subscribeToJourney = subscribeToJourney
679
734
}
680
735
Object . defineProperty ( client , 'profile' , { value : profile } )
681
736
return client
0 commit comments