Skip to content

Commit 89a7827

Browse files
committed
subscribeToJourney() WIP
1 parent 360d46a commit 89a7827

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

index.js

+55
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,60 @@ const createClient = (profile, userAgent, opt = {}) => {
656656
}
657657
}
658658

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+
659713
const client = {
660714
departures,
661715
arrivals,
@@ -676,6 +730,7 @@ const createClient = (profile, userAgent, opt = {}) => {
676730
client.createSubscriptionsUser = createSubscriptionsUser
677731
client.subscriptions = subscriptions
678732
client.subscription = subscription
733+
client.subscribeToJourney = subscribeToJourney
679734
}
680735
Object.defineProperty(client, 'profile', {value: profile})
681736
return client

0 commit comments

Comments
 (0)