@onereach/step-voice 6.0.0 → 6.0.1

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.
@@ -142,6 +142,7 @@ class GlobalCommand extends voice_1.default {
142
142
  case 'background': {
143
143
  this.event.processed = true;
144
144
  this.thread.background = event.params.background ?? false;
145
+ await this.handleHeartbeat(call);
145
146
  break;
146
147
  }
147
148
  default:
package/dst/step.d.ts CHANGED
@@ -10,11 +10,6 @@ export interface IConversation {
10
10
  export interface IConversationData {
11
11
  _conv: IConversation;
12
12
  }
13
- export declare const enum ConvThreadType {
14
- lcl = "lcl",
15
- glb = "glb",
16
- wrk = "wrk"
17
- }
18
13
  export default class ConvStep<TData extends IConversationData, TIn = unknown, TOut = unknown, TParams = any> extends Step<TIn & ConvStepDataIn, TOut, TParams> {
19
14
  private convDataCache?;
20
15
  get cache(): TData | undefined;
@@ -24,7 +19,6 @@ export default class ConvStep<TData extends IConversationData, TIn = unknown, TO
24
19
  /** id of the thread where conversation data is stored */
25
20
  get dataThreadId(): IThreadId;
26
21
  get isGlobal(): boolean;
27
- get threadType(): ConvThreadType;
28
22
  get isWorker(): boolean;
29
23
  get useQueue(): boolean;
30
24
  fetchData(): Promise<TData>;
package/dst/step.js CHANGED
@@ -3,15 +3,6 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const tslib_1 = require("tslib");
5
5
  const step_1 = tslib_1.__importDefault(require("@onereach/flow-sdk/dst/step"));
6
- // eslint-disable-next-line @typescript-eslint/no-redeclare
7
- // interface IConversationStep {
8
- // key: string
9
- // trd: string
10
- // typ?: string
11
- // name?: string // for debug
12
- // label?: string // for debug
13
- // step?: string // for debug
14
- // }
15
6
  class ConvStep extends step_1.default {
16
7
  get cache() {
17
8
  return this.convDataCache;
@@ -45,13 +36,8 @@ class ConvStep extends step_1.default {
45
36
  get isGlobal() {
46
37
  return false;
47
38
  }
48
- get threadType() {
49
- return this.thread.id === this.workerThreadId
50
- ? (this.isGlobal ? "glb" /* ConvThreadType.glb */ : "wrk" /* ConvThreadType.wrk */)
51
- : "lcl" /* ConvThreadType.lcl */;
52
- }
53
39
  get isWorker() {
54
- return this.threadType !== "lcl" /* ConvThreadType.lcl */;
40
+ return this.thread.id === this.workerThreadId;
55
41
  }
56
42
  get useQueue() {
57
43
  return true;
@@ -113,12 +99,9 @@ class ConvStep extends step_1.default {
113
99
  delete this.state.prevSkipName;
114
100
  }
115
101
  async cancel() {
116
- if (this.isWorker) {
102
+ if (this.isGlobal) {
117
103
  this.log.debug('conv.cannot cancel global');
118
- // return
119
104
  }
120
- // const activeStep = await this.activeStep(this.isWorker)
121
- // await this.sendEventToStep({ event: { name: '_conv', action: 'onCancel', params: { byStep: this.step.label } }, toStep: activeStep })
122
105
  }
123
106
  async onCancel() {
124
107
  // await this.popConvStep()
@@ -136,11 +119,6 @@ class ConvStep extends step_1.default {
136
119
  async onAwake() {
137
120
  this.state.name = this.state.resumeState;
138
121
  this.state.resumeState = undefined;
139
- // const conv = await this.getConversation()
140
- // if (this.isWorker && conv.glb.length === 1) {
141
- // this.log.debug('make global thread foreground')
142
- // this.thread.background = false
143
- // }
144
122
  }
145
123
  async onPause() {
146
124
  this.state.resumeState = this.state.prevName;
@@ -152,18 +130,6 @@ class ConvStep extends step_1.default {
152
130
  }
153
131
  async notifyConvEnd({ onlyLocal } = {}) {
154
132
  this.log.debug('notifyConvEnd', { onlyLocal });
155
- // const conv = await this.getConversation()
156
- // const lcl = conv.lcl.splice(0)
157
- // const wrk = onlyLocal ? [] : conv.glb.splice(0)
158
- // if (lcl.length > 0 || wrk.length > 0) {
159
- // await this.updateData()
160
- // for (const step of lcl) {
161
- // await this.sendEventToStep({ toStep: step, action: 'onConvEnd' })
162
- // }
163
- // for (const step of wrk) {
164
- // await this.sendEventToStep({ toStep: step, action: 'onConvEnd' })
165
- // }
166
- // }
167
133
  }
168
134
  async waitConvEnd() {
169
135
  const workerThread = this.process.getThread(this.workerThreadId);
@@ -188,26 +154,8 @@ class ConvStep extends step_1.default {
188
154
  this.end();
189
155
  }
190
156
  async pause() {
191
- // const conv = await this._getConversation()
192
- // const activeStep = await this.activeStep(false)
193
- // if (activeStep != null) {
194
- // this.log.debug('conv.pause', activeStep)
195
- // conv.stk.push(conv.lcl.splice(0)) // save que to stk
196
- // await this.updateData()
197
- // await this.sendEventToStep({ action: 'onPause', toStep: activeStep })
198
- // } else {
199
- // this.log.debug('conv.nothing to pause')
200
- // }
201
157
  }
202
158
  async resume() {
203
- // const conv = await this._getConversation()
204
- // if (conv.stk.length> 0) {
205
- // conv.lcl.unshift(...(conv.stk.pop() ?? [])) // restore que from stk
206
- // await this.updateData()
207
- // await this.sendEventToStep({ toGlobal: false, action: 'onResume' })
208
- // } else {
209
- // this.log.debug('conv.nothing to resume')
210
- // }
211
159
  }
212
160
  async startConversation(data, { thread: _thread } = {}) {
213
161
  this.convDataCache = {
package/dst/voice.js CHANGED
@@ -16,15 +16,6 @@ class VoiceStep extends step_1.default {
16
16
  async runBefore() {
17
17
  await super.runBefore();
18
18
  if (this.cache != null) {
19
- // if (!this.event.processed && this.event.action == null) {
20
- // const toWorker = this.event.params.global
21
- // const hasHandler = await this.sendEventToStep({ event: { ...this.event, action: toWorker ? 'wrk' : 'lcl' }, toWorker }) // redirect to global (1)
22
- // if (hasHandler != null) {
23
- // this.log.debug('hasWorker', { hasGlobal: hasHandler })
24
- // this.state.prevSkipName = this.state.name
25
- // this.state.name = 'onSkipEvent'
26
- // }
27
- // }
28
19
  await this.handleHeartbeat(this.cache);
29
20
  }
30
21
  }
@@ -53,10 +44,20 @@ class VoiceStep extends step_1.default {
53
44
  }
54
45
  async handleHeartbeat(call) {
55
46
  if (call.vv >= 1) {
47
+ if (this.thread.background) {
48
+ delete this.waits.timeout;
49
+ return;
50
+ }
56
51
  const expectHearbeatBefore = Date.now() + 290000;
57
52
  this.triggers.deadline(expectHearbeatBefore, () => {
58
- this.end();
59
- this.throwError(new Error('missing heartbeat, call is probably already hangup'));
53
+ this.thread.background = true;
54
+ if (call.ended) {
55
+ this.log.warn('missing heartbeat, call is ended');
56
+ this.end();
57
+ }
58
+ else {
59
+ this.log.error('missing heartbeat, call is probably already hangup');
60
+ }
60
61
  });
61
62
  }
62
63
  else if (call.vv !== 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onereach/step-voice",
3
- "version": "6.0.0",
3
+ "version": "6.0.1",
4
4
  "author": "Roman Zolotarov <roman.zolotarov@onereach.com>",
5
5
  "contributors": [
6
6
  "Roman Zolotarov",