forked from rogertalk/go-avs
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathevent.go
622 lines (536 loc) · 16.6 KB
/
event.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
package avs
import (
"time"
)
// newEvent creates a Message suited for being used as an event value.
func newEvent(namespace, name, messageId, dialogRequestId string) *Message {
m := &Message{
Header: map[string]string{
"namespace": namespace,
"name": name,
"messageId": messageId,
},
Payload: nil,
}
if dialogRequestId != "" {
m.Header["dialogRequestId"] = dialogRequestId
}
return m
}
/********** Alerts **********/
// The AlertEnteredBackground event.
type AlertEnteredBackground struct {
*Message
Payload struct {
Token string `json:"token"`
} `json:"payload"`
}
func NewAlertEnteredBackground(messageId, token string) *AlertEnteredBackground {
m := new(AlertEnteredBackground)
m.Message = newEvent("Alerts", "AlertEnteredBackground", messageId, "")
m.Payload.Token = token
return m
}
// The AlertEnteredForeground event.
type AlertEnteredForeground struct {
*Message
Payload struct {
Token string `json:"token"`
} `json:"payload"`
}
func NewAlertEnteredForeground(messageId, token string) *AlertEnteredForeground {
m := new(AlertEnteredForeground)
m.Message = newEvent("Alerts", "AlertEnteredForeground", messageId, "")
m.Payload.Token = token
return m
}
// The AlertStarted event.
type AlertStarted struct {
*Message
Payload struct {
Token string `json:"token"`
} `json:"payload"`
}
func NewAlertStarted(messageId, token string) *AlertStarted {
m := new(AlertStarted)
m.Message = newEvent("Alerts", "AlertStarted", messageId, "")
m.Payload.Token = token
return m
}
// The AlertStopped event.
type AlertStopped struct {
*Message
Payload struct {
Token string `json:"token"`
} `json:"payload"`
}
func NewAlertStopped(messageId, token string) *AlertStopped {
m := new(AlertStopped)
m.Message = newEvent("Alerts", "AlertStopped", messageId, "")
m.Payload.Token = token
return m
}
// The DeleteAlertFailed event.
type DeleteAlertFailed struct {
*Message
Payload struct {
Token string `json:"token"`
} `json:"payload"`
}
func NewDeleteAlertFailed(messageId, token string) *DeleteAlertFailed {
m := new(DeleteAlertFailed)
m.Message = newEvent("Alerts", "DeleteAlertFailed", messageId, "")
m.Payload.Token = token
return m
}
// The DeleteAlertSucceeded event.
type DeleteAlertSucceeded struct {
*Message
Payload struct {
Token string `json:"token"`
} `json:"payload"`
}
func NewDeleteAlertSucceeded(messageId, token string) *DeleteAlertSucceeded {
m := new(DeleteAlertSucceeded)
m.Message = newEvent("Alerts", "DeleteAlertSucceeded", messageId, "")
m.Payload.Token = token
return m
}
// The SetAlertFailed event.
type SetAlertFailed struct {
*Message
Payload struct {
Token string `json:"token"`
} `json:"payload"`
}
func NewSetAlertFailed(messageId, token string) *SetAlertFailed {
m := new(SetAlertFailed)
m.Message = newEvent("Alerts", "SetAlertFailed", messageId, "")
m.Payload.Token = token
return m
}
// The SetAlertSucceeded event.
type SetAlertSucceeded struct {
*Message
Payload struct {
Token string `json:"token"`
} `json:"payload"`
}
func NewSetAlertSucceeded(messageId, token string) *SetAlertSucceeded {
m := new(SetAlertSucceeded)
m.Message = newEvent("Alerts", "SetAlertSucceeded", messageId, "")
m.Payload.Token = token
return m
}
/********** AudioPlayer **********/
// Also used by the PlaybackState context.
type playbackState struct {
Token string `json:"token"`
OffsetInMilliseconds int `json:"offsetInMilliseconds"`
PlayerActivity PlayerActivity `json:"playerActivity"`
}
// The PlaybackFailed event.
type PlaybackFailed struct {
*Message
Payload struct {
Token string `json:"token"`
CurrentPlaybackState playbackState `json:"currentPlaybackState"`
Error struct {
Type MediaErrorType `json:"type"`
Message string `json:"message"`
} `json:"error"`
} `json:"payload"`
}
func NewPlaybackFailed(messageId, token string, errorType MediaErrorType, errorMessage string) *PlaybackFailed {
m := new(PlaybackFailed)
m.Message = newEvent("AudioPlayer", "PlaybackFailed", messageId, "")
m.Payload.Token = token
m.Payload.Error.Type = errorType
m.Payload.Error.Message = errorMessage
return m
}
// The PlaybackFinished event.
type PlaybackFinished struct {
*Message
Payload struct {
Token string `json:"token"`
OffsetInMilliseconds int `json:"offsetInMilliseconds"`
} `json:"payload"`
}
func NewPlaybackFinished(messageId, token string, offset time.Duration) *PlaybackFinished {
m := new(PlaybackFinished)
m.Message = newEvent("AudioPlayer", "PlaybackFinished", messageId, "")
m.Payload.Token = token
m.Payload.OffsetInMilliseconds = int(offset.Seconds() * 1000)
return m
}
// The PlaybackNearlyFinished event.
type PlaybackNearlyFinished struct {
*Message
Payload struct {
Token string `json:"token"`
OffsetInMilliseconds int `json:"offsetInMilliseconds"`
} `json:"payload"`
}
func NewPlaybackNearlyFinished(messageId, token string, offset time.Duration) *PlaybackNearlyFinished {
m := new(PlaybackNearlyFinished)
m.Message = newEvent("AudioPlayer", "PlaybackNearlyFinished", messageId, "")
m.Payload.Token = token
m.Payload.OffsetInMilliseconds = int(offset.Seconds() * 1000)
return m
}
// The PlaybackPaused event.
type PlaybackPaused struct {
*Message
Payload struct {
Token string `json:"token"`
OffsetInMilliseconds int `json:"offsetInMilliseconds"`
} `json:"payload"`
}
func NewPlaybackPaused(messageId, token string, offset time.Duration) *PlaybackPaused {
m := new(PlaybackPaused)
m.Message = newEvent("AudioPlayer", "PlaybackPaused", messageId, "")
m.Payload.Token = token
m.Payload.OffsetInMilliseconds = int(offset.Seconds() * 1000)
return m
}
// The PlaybackQueueCleared event.
type PlaybackQueueCleared struct {
*Message
Payload struct{} `json:"payload"`
}
func NewPlaybackQueueCleared(messageId string) *PlaybackQueueCleared {
m := new(PlaybackQueueCleared)
m.Message = newEvent("AudioPlayer", "PlaybackQueueCleared", messageId, "")
return m
}
// The PlaybackResumed event.
type PlaybackResumed struct {
*Message
Payload struct {
Token string `json:"token"`
OffsetInMilliseconds int `json:"offsetInMilliseconds"`
} `json:"payload"`
}
func NewPlaybackResumed(messageId, token string, offset time.Duration) *PlaybackResumed {
m := new(PlaybackResumed)
m.Message = newEvent("AudioPlayer", "PlaybackResumed", messageId, "")
m.Payload.Token = token
m.Payload.OffsetInMilliseconds = int(offset.Seconds() * 1000)
return m
}
// The PlaybackStarted event.
type PlaybackStarted struct {
*Message
Payload struct {
Token string `json:"token"`
OffsetInMilliseconds int `json:"offsetInMilliseconds"`
} `json:"payload"`
}
func NewPlaybackStarted(messageId, token string, offset time.Duration) *PlaybackStarted {
m := new(PlaybackStarted)
m.Message = newEvent("AudioPlayer", "PlaybackStarted", messageId, "")
m.Payload.Token = token
m.Payload.OffsetInMilliseconds = int(offset.Seconds() * 1000)
return m
}
// The PlaybackStopped event.
type PlaybackStopped struct {
*Message
Payload struct {
Token string `json:"token"`
OffsetInMilliseconds int `json:"offsetInMilliseconds"`
} `json:"payload"`
}
func NewPlaybackStopped(messageId, token string, offset time.Duration) *PlaybackStopped {
m := new(PlaybackStopped)
m.Message = newEvent("AudioPlayer", "PlaybackStopped", messageId, "")
m.Payload.Token = token
m.Payload.OffsetInMilliseconds = int(offset.Seconds() * 1000)
return m
}
// The PlaybackStutterStarted event.
type PlaybackStutterStarted struct {
*Message
Payload struct {
Token string `json:"token"`
OffsetInMilliseconds int `json:"offsetInMilliseconds"`
} `json:"payload"`
}
func NewPlaybackStutterStarted(messageId, token string, offset time.Duration) *PlaybackStutterStarted {
m := new(PlaybackStutterStarted)
m.Message = newEvent("AudioPlayer", "PlaybackStutterStarted", messageId, "")
m.Payload.Token = token
m.Payload.OffsetInMilliseconds = int(offset.Seconds() * 1000)
return m
}
// The PlaybackStutterFinished event.
type PlaybackStutterFinished struct {
*Message
Payload struct {
Token string `json:"token"`
OffsetInMilliseconds int `json:"offsetInMilliseconds"`
StutterDurationInMilliseconds int `json:"stutterDurationInMilliseconds"`
} `json:"payload"`
}
func NewPlaybackStutterFinished(messageId, token string, offset, stutterDuration time.Duration) *PlaybackStutterFinished {
m := new(PlaybackStutterFinished)
m.Message = newEvent("AudioPlayer", "PlaybackStutterFinished", messageId, "")
m.Payload.Token = token
m.Payload.OffsetInMilliseconds = int(offset.Seconds() * 1000)
m.Payload.StutterDurationInMilliseconds = int(stutterDuration.Seconds() * 1000)
return m
}
// The ProgressReportDelayElapsed event.
type ProgressReportDelayElapsed struct {
*Message
Payload struct {
Token string `json:"token"`
OffsetInMilliseconds int `json:"offsetInMilliseconds"`
} `json:"payload"`
}
func NewProgressReportDelayElapsed(messageId, token string, offset time.Duration) *ProgressReportDelayElapsed {
m := new(ProgressReportDelayElapsed)
m.Message = newEvent("AudioPlayer", "ProgressReportDelayElapsed", messageId, "")
m.Payload.Token = token
m.Payload.OffsetInMilliseconds = int(offset.Seconds() * 1000)
return m
}
// The ProgressReportIntervalElapsed event.
type ProgressReportIntervalElapsed struct {
*Message
Payload struct {
Token string `json:"token"`
OffsetInMilliseconds int `json:"offsetInMilliseconds"`
} `json:"payload"`
}
func NewProgressReportIntervalElapsed(messageId, token string, offset time.Duration) *ProgressReportIntervalElapsed {
m := new(ProgressReportIntervalElapsed)
m.Message = newEvent("AudioPlayer", "ProgressReportIntervalElapsed", messageId, "")
m.Payload.Token = token
m.Payload.OffsetInMilliseconds = int(offset.Seconds() * 1000)
return m
}
// The StreamMetadataExtracted event.
type StreamMetadataExtracted struct {
*Message
Payload struct {
Token string `json:"token"`
Metadata map[string]interface{} `json:"metadata"`
} `json:"payload"`
}
func NewStreamMetadataExtracted(messageId, token string, metadata map[string]interface{}) *StreamMetadataExtracted {
m := new(StreamMetadataExtracted)
m.Message = newEvent("AudioPlayer", "StreamMetadataExtracted", messageId, "")
m.Payload.Token = token
m.Payload.Metadata = metadata
return m
}
/********** PlaybackController **********/
// The NextCommandIssued event.
type NextCommandIssued struct {
*Message
Payload struct{} `json:"payload"`
}
func NewNextCommandIssued(messageId string) *NextCommandIssued {
m := new(NextCommandIssued)
m.Message = newEvent("PlaybackController", "NextCommandIssued", messageId, "")
return m
}
// The PauseCommandIssued event.
type PauseCommandIssued struct {
*Message
Payload struct{} `json:"payload"`
}
func NewPauseCommandIssued(messageId string) *PauseCommandIssued {
m := new(PauseCommandIssued)
m.Message = newEvent("PlaybackController", "PauseCommandIssued", messageId, "")
return m
}
// The PlayCommandIssued event.
type PlayCommandIssued struct {
*Message
Payload struct{} `json:"payload"`
}
func NewPlayCommandIssued(messageId string) *PlayCommandIssued {
m := new(PlayCommandIssued)
m.Message = newEvent("PlaybackController", "PlayCommandIssued", messageId, "")
return m
}
// The PreviousCommandIssued event.
type PreviousCommandIssued struct {
*Message
Payload struct{} `json:"payload"`
}
func NewPreviousCommandIssued(messageId string) *PreviousCommandIssued {
m := new(PreviousCommandIssued)
m.Message = newEvent("PlaybackController", "PreviousCommandIssued", messageId, "")
return m
}
/********** Speaker **********/
// The MuteChanged event.
type MuteChanged struct {
*Message
Payload struct {
Volume int `json:"volume"`
Muted bool `json:"muted"`
} `json:"payload"`
}
func NewMuteChanged(messageId string, volume int, muted bool) *MuteChanged {
m := new(MuteChanged)
m.Message = newEvent("Speaker", "MuteChanged", messageId, "")
m.Payload.Volume = volume
m.Payload.Muted = muted
return m
}
// The VolumeChanged event.
type VolumeChanged struct {
*Message
Payload struct {
Volume int `json:"volume"`
Muted bool `json:"muted"`
} `json:"payload"`
}
func NewVolumeChanged(messageId string, volume int, muted bool) *VolumeChanged {
m := new(VolumeChanged)
m.Message = newEvent("Speaker", "VolumeChanged", messageId, "")
m.Payload.Volume = volume
m.Payload.Muted = muted
return m
}
/********** SpeechRecognizer **********/
// The ExpectSpeechTimedOut event.
type ExpectSpeechTimedOut struct {
*Message
Payload struct{} `json:"payload"`
}
func NewExpectSpeechTimedOut(messageId string) *ExpectSpeechTimedOut {
m := new(ExpectSpeechTimedOut)
m.Message = newEvent("SpeechRecognizer", "ExpectSpeechTimedOut", messageId, "")
return m
}
// RecognizeProfile identifies the ASR profile associated with your product.
type RecognizeProfile string
// Possible values for RecognizeProfile.
// Supports three distinct profiles optimized for speech at varying distances.
const (
RecognizeProfileCloseTalk = RecognizeProfile("CLOSE_TALK")
RecognizeProfileNearField = RecognizeProfile("NEAR_FIELD")
RecognizeProfileFarField = RecognizeProfile("FAR_FIELD")
)
// The Recognize event.
type Recognize struct {
*Message
Payload struct {
Profile RecognizeProfile `json:"profile"`
Format string `json:"format"`
} `json:"payload"`
}
func NewRecognize(messageId, dialogRequestId string) *Recognize {
return NewRecognizeWithProfile(messageId, dialogRequestId, RecognizeProfileCloseTalk)
}
func NewRecognizeWithProfile(messageId, dialogRequestId string, profile RecognizeProfile) *Recognize {
m := new(Recognize)
m.Message = newEvent("SpeechRecognizer", "Recognize", messageId, dialogRequestId)
m.Payload.Format = "AUDIO_L16_RATE_16000_CHANNELS_1"
m.Payload.Profile = profile
return m
}
/********** SpeechSynthesizer **********/
// The SpeechFinished event.
type SpeechFinished struct {
*Message
Payload struct {
Token string `json:"token"`
} `json:"payload"`
}
func NewSpeechFinished(messageId, token string) *SpeechFinished {
m := new(SpeechFinished)
m.Message = newEvent("SpeechSynthesizer", "SpeechFinished", messageId, "")
m.Payload.Token = token
return m
}
// The SpeechStarted event.
type SpeechStarted struct {
*Message
Payload struct {
Token string `json:"token"`
} `json:"payload"`
}
func NewSpeechStarted(messageId, token string) *SpeechStarted {
m := new(SpeechStarted)
m.Message = newEvent("SpeechSynthesizer", "SpeechStarted", messageId, "")
m.Payload.Token = token
return m
}
/********** Settings **********/
// The SettingsUpdated event.
type Setting struct {
Key string `json:"key"`
Value string `json:"value"`
}
type SettingsUpdated struct {
*Message
Payload struct {
Settings []Setting `json:"settings"`
} `json:"payload"`
}
type SettingLocale string
// Possible values for SettingLocale.
const (
SettingLocaleUS = SettingLocale("en-US")
SettingLocaleGB = SettingLocale("en-GB")
SettingLocaleDE = SettingLocale("de-DE")
)
func NewLocaleSettingsUpdated(messageId string, locale SettingLocale) *SettingsUpdated {
m := new(SettingsUpdated)
m.Message = newEvent("Settings", "SettingsUpdated", messageId, "")
m.Payload.Settings = append(m.Payload.Settings, Setting{
Key: "locale",
Value: string(locale),
})
return m
}
/********** System **********/
// The ExceptionEncountered event.
type ExceptionEncountered struct {
*Message
Payload struct {
UnparsedDirective string `json:"unparsedDirective"`
Error struct {
Type ErrorType `json:"type"`
Message string `json:"message"`
} `json:"error"`
} `json:"payload"`
}
func NewExceptionEncountered(messageId, directive string, errorType ErrorType, errorMessage string) *ExceptionEncountered {
m := new(ExceptionEncountered)
m.Message = newEvent("System", "ExceptionEncountered", messageId, "")
m.Payload.UnparsedDirective = directive
m.Payload.Error.Type = errorType
m.Payload.Error.Message = errorMessage
return m
}
// The SynchronizeState event.
type SynchronizeState struct {
*Message
Payload struct{} `json:"payload"`
}
func NewSynchronizeState(messageId string) *SynchronizeState {
m := new(SynchronizeState)
m.Message = newEvent("System", "SynchronizeState", messageId, "")
return m
}
// The UserInactivityReport event.
type UserInactivityReport struct {
*Message
Payload struct {
InactiveTimeInSeconds int `json:"inactiveTimeInSeconds"`
} `json:"payload"`
}
func NewUserInactivityReport(messageId string, inactiveTime time.Duration) *UserInactivityReport {
m := new(UserInactivityReport)
m.Message = newEvent("System", "UserInactivityReport", messageId, "")
m.Payload.InactiveTimeInSeconds = int(inactiveTime.Seconds())
return m
}