github.com/CyCoreSystems/ari@v4.8.4+incompatible/events.go (about) 1 package ari 2 3 import "strings" 4 5 // Event is the top level event interface 6 type Event interface { 7 // GetApplication returns the name of the ARI application to which this event is associated 8 GetApplication() string 9 10 // GetDialog returns any dialog by which this event has been tagged 11 GetDialog() string 12 13 // GetNode returns the unique ID of the Asterisk system on which this event originated 14 GetNode() string 15 16 // GetType returns the type name of this event 17 GetType() string 18 19 // Key returns a key using the location information from the Event 20 Key(kind, id string) *Key 21 22 // Keys returns the related entity keys for the event 23 Keys() Keys 24 25 // SetDialog tags the event with a Dialog 26 SetDialog(string) 27 } 28 29 // EventData provides the basic metadata for an ARI event 30 type EventData struct { 31 // Application indicates the ARI application which emitted this event 32 Application string `json:"application"` 33 34 // Dialog indicates a dialog to which the event has been bound 35 Dialog string `json:"dialog,omitempty"` 36 37 // Node indicates the unique identifier of the source Asterisk box for this event 38 Node string `json:"asterisk_id,omitempty"` 39 40 // Timestamp indicates the time this event was generated 41 Timestamp DateTime `json:"timestamp,omitempty"` 42 43 // Type is the type name of this event 44 Type string `json:"type"` 45 } 46 47 // GetApplication gets the application of the event 48 func (e *EventData) GetApplication() string { 49 return e.Application 50 } 51 52 // GetDialog gets the dialog, if present, to which this event has been tagged 53 func (e *EventData) GetDialog() string { 54 return e.Dialog 55 } 56 57 // GetNode gets the node ID of the source Asterisk instance 58 func (e *EventData) GetNode() string { 59 return e.Node 60 } 61 62 // GetType gets the type of the event 63 func (e *EventData) GetType() string { 64 return e.Type 65 } 66 67 // Key returns a new, fully qualified key from the EventData 68 func (e *EventData) Key(kind, id string) *Key { 69 return &Key{ 70 App: e.Application, 71 Dialog: e.Dialog, 72 ID: id, 73 Kind: kind, 74 Node: e.Node, 75 } 76 } 77 78 // SetDialog tags the event with the given dialog ID. If a dialog is already set, it will be overwritten. 79 func (e *EventData) SetDialog(id string) { 80 e.Dialog = id 81 } 82 83 // implementations of events 84 85 // Keys returns the list of keys associated with this event 86 func (evt *ApplicationReplaced) Keys() (sx Keys) { 87 return 88 } 89 90 // Keys returns the list of keys associated with this event 91 func (evt *BridgeAttendedTransfer) Keys() (sx Keys) { 92 if id := evt.DestinationThreewayBridge.ID; id != "" { 93 sx = append(sx, evt.Key(BridgeKey, id)) 94 } 95 if id := evt.TransfererFirstLegBridge.ID; id != "" { 96 sx = append(sx, evt.Key(BridgeKey, id)) 97 } 98 if id := evt.TransfererSecondLegBridge.ID; id != "" { 99 sx = append(sx, evt.Key(BridgeKey, id)) 100 } 101 102 if id := evt.DestinationLinkFirstLeg.ID; id != "" { 103 sx = append(sx, evt.Key(ChannelKey, id)) 104 } 105 if id := evt.DestinationLinkSecondLeg.ID; id != "" { 106 sx = append(sx, evt.Key(ChannelKey, id)) 107 } 108 if id := evt.DestinationThreewayChannel.ID; id != "" { 109 sx = append(sx, evt.Key(ChannelKey, id)) 110 } 111 if id := evt.ReplaceChannel.ID; id != "" { 112 sx = append(sx, evt.Key(ChannelKey, id)) 113 } 114 if id := evt.Transferee.ID; id != "" { 115 sx = append(sx, evt.Key(ChannelKey, id)) 116 } 117 if id := evt.TransfererFirstLeg.ID; id != "" { 118 sx = append(sx, evt.Key(ChannelKey, id)) 119 } 120 if id := evt.TransfererSecondLeg.ID; id != "" { 121 sx = append(sx, evt.Key(ChannelKey, id)) 122 } 123 if id := evt.TransferTarget.ID; id != "" { 124 sx = append(sx, evt.Key(ChannelKey, id)) 125 } 126 return 127 } 128 129 // Keys returns the list of keys associated with this event 130 func (evt *BridgeBlindTransfer) Keys() (sx Keys) { 131 132 sx = append(sx, evt.Key(BridgeKey, evt.Bridge.ID)) 133 for _, id := range evt.Bridge.ChannelIDs { 134 sx = append(sx, evt.Key(ChannelKey, id)) 135 } 136 137 sx = append(sx, evt.Key(ChannelKey, evt.Channel.ID)) 138 139 if id := evt.ReplaceChannel.ID; id != "" { 140 sx = append(sx, evt.Key(ChannelKey, id)) 141 } 142 if id := evt.Transferee.ID; id != "" { 143 sx = append(sx, evt.Key(ChannelKey, id)) 144 } 145 return 146 } 147 148 // Keys returns the list of keys associated with this event 149 func (evt *BridgeCreated) Keys() (sx Keys) { 150 151 sx = append(sx, evt.Key(BridgeKey, evt.Bridge.ID)) 152 for _, id := range evt.Bridge.ChannelIDs { 153 sx = append(sx, evt.Key(ChannelKey, id)) 154 } 155 156 for _, id := range evt.Bridge.ChannelIDs { 157 sx = append(sx, evt.Key(ChannelKey, id)) 158 } 159 return 160 } 161 162 // Keys returns the list of keys associated with this event 163 func (evt *BridgeDestroyed) Keys() (sx Keys) { 164 165 sx = append(sx, evt.Key(BridgeKey, evt.Bridge.ID)) 166 for _, id := range evt.Bridge.ChannelIDs { 167 sx = append(sx, evt.Key(ChannelKey, id)) 168 } 169 170 return 171 } 172 173 // Keys returns the list of keys associated with this event 174 func (evt *BridgeMerged) Keys() (sx Keys) { 175 176 sx = append(sx, evt.Key(BridgeKey, evt.Bridge.ID)) 177 for _, id := range evt.Bridge.ChannelIDs { 178 sx = append(sx, evt.Key(ChannelKey, id)) 179 } 180 181 sx = append(sx, evt.Key(BridgeKey, evt.BridgeFrom.ID)) 182 for _, id := range evt.BridgeFrom.ChannelIDs { 183 sx = append(sx, evt.Key(ChannelKey, id)) 184 } 185 186 return 187 } 188 189 // Keys returns the list of keys associated with this event 190 func (evt *BridgeVideoSourceChanged) Keys() (sx Keys) { 191 192 sx = append(sx, evt.Key(BridgeKey, evt.Bridge.ID)) 193 for _, id := range evt.Bridge.ChannelIDs { 194 sx = append(sx, evt.Key(ChannelKey, id)) 195 } 196 197 return 198 } 199 200 // Keys returns the list of keys associated with this event 201 func (evt *ChannelCallerID) Keys() (sx Keys) { 202 sx = append(sx, evt.Key(ChannelKey, evt.Channel.ID)) 203 return 204 } 205 206 // Keys returns the list of keys associated with this event 207 func (evt *ChannelConnectedLine) Keys() (sx Keys) { 208 sx = append(sx, evt.Key(ChannelKey, evt.Channel.ID)) 209 return 210 } 211 212 // Keys returns the list of keys associated with this event 213 func (evt *ChannelCreated) Keys() (sx Keys) { 214 sx = append(sx, evt.Key(ChannelKey, evt.Channel.ID)) 215 return 216 } 217 218 // Keys returns the list of keys associated with this event 219 func (evt *ChannelDestroyed) Keys() (sx Keys) { 220 sx = append(sx, evt.Key(ChannelKey, evt.Channel.ID)) 221 return 222 } 223 224 // Keys returns the list of keys associated with this event 225 func (evt *ChannelDialplan) Keys() (sx Keys) { 226 sx = append(sx, evt.Key(ChannelKey, evt.Channel.ID)) 227 return 228 } 229 230 // Keys returns the list of keys associated with this event 231 func (evt *ChannelDtmfReceived) Keys() (sx Keys) { 232 sx = append(sx, evt.Key(ChannelKey, evt.Channel.ID)) 233 return 234 } 235 236 // Keys returns the list of keys associated with this event 237 func (evt *ChannelEnteredBridge) Keys() (sx Keys) { 238 sx = append(sx, evt.Key(ChannelKey, evt.Channel.ID)) 239 sx = append(sx, evt.Key(BridgeKey, evt.Bridge.ID)) 240 for _, id := range evt.Bridge.ChannelIDs { 241 sx = append(sx, evt.Key(ChannelKey, id)) 242 243 } 244 return 245 } 246 247 // Keys returns the list of keys associated with this event 248 func (evt *ChannelHangupRequest) Keys() (sx Keys) { 249 sx = append(sx, evt.Key(ChannelKey, evt.Channel.ID)) 250 return 251 } 252 253 // Keys returns the list of keys associated with this event 254 func (evt *ChannelHold) Keys() (sx Keys) { 255 sx = append(sx, evt.Key(ChannelKey, evt.Channel.ID)) 256 return 257 } 258 259 // Keys returns the list of keys associated with this event 260 func (evt *ChannelLeftBridge) Keys() (sx Keys) { 261 sx = append(sx, evt.Key(ChannelKey, evt.Channel.ID)) 262 sx = append(sx, evt.Key(BridgeKey, evt.Bridge.ID)) 263 for _, id := range evt.Bridge.ChannelIDs { 264 sx = append(sx, evt.Key(ChannelKey, id)) 265 266 } 267 return 268 } 269 270 // Keys returns the list of keys associated with this event 271 func (evt *ChannelStateChange) Keys() (sx Keys) { 272 sx = append(sx, evt.Key(ChannelKey, evt.Channel.ID)) 273 return 274 } 275 276 // Keys returns the list of keys associated with this event 277 func (evt *ChannelTalkingFinished) Keys() (sx Keys) { 278 sx = append(sx, evt.Key(ChannelKey, evt.Channel.ID)) 279 return 280 } 281 282 // Keys returns the list of keys associated with this event 283 func (evt *ChannelTalkingStarted) Keys() (sx Keys) { 284 sx = append(sx, evt.Key(ChannelKey, evt.Channel.ID)) 285 return 286 } 287 288 // Keys returns the list of keys associated with this event 289 func (evt *ChannelUnhold) Keys() (sx Keys) { 290 sx = append(sx, evt.Key(ChannelKey, evt.Channel.ID)) 291 return 292 } 293 294 // Keys returns the list of keys associated with this event 295 func (evt *ChannelUserevent) Keys() (sx Keys) { 296 sx = append(sx, evt.Key(ChannelKey, evt.Channel.ID)) 297 sx = append(sx, evt.Key(BridgeKey, evt.Bridge.ID)) 298 for _, i := range evt.Bridge.ChannelIDs { 299 sx = append(sx, evt.Key(ChannelKey, i)) 300 } 301 302 sx = append(sx, evt.Key(EndpointKey, endpointKeyID(evt.Endpoint.Technology, evt.Endpoint.Resource))) 303 for _, i := range evt.Endpoint.ChannelIDs { 304 sx = append(sx, evt.Key(ChannelKey, i)) 305 } 306 return 307 } 308 309 // Keys returns the list of keys associated with this event 310 func (evt *ChannelVarset) Keys() (sx Keys) { 311 sx = append(sx, evt.Key(ChannelKey, evt.Channel.ID)) 312 return 313 } 314 315 // Keys returns the list of keys associated with this event 316 func (evt *ContactInfo) Keys() (sx Keys) { 317 return 318 } 319 320 // Keys returns the list of keys associated with this event 321 func (evt *ContactStatusChange) Keys() (sx Keys) { 322 sx = append(sx, evt.Key(EndpointKey, endpointKeyID(evt.Endpoint.Technology, evt.Endpoint.Resource))) 323 return 324 } 325 326 // Keys returns the list of keys associated with this event 327 func (evt *DeviceStateChanged) Keys() (sx Keys) { 328 sx = append(sx, evt.DeviceState.Key) 329 return 330 } 331 332 // Keys returns the list of keys associated with this event 333 func (evt *Dial) Keys() (sx Keys) { 334 sx = append(sx, evt.Key(ChannelKey, evt.Caller.ID)) 335 sx = append(sx, evt.Key(ChannelKey, evt.Peer.ID)) 336 sx = append(sx, evt.Key(ChannelKey, evt.Forwarded.ID)) 337 338 return 339 } 340 341 // Keys returns the list of keys associated with this event 342 func (evt *EndpointStateChange) Keys() (sx Keys) { 343 sx = append(sx, evt.Key(EndpointKey, endpointKeyID(evt.Endpoint.Technology, evt.Endpoint.Resource))) 344 return 345 } 346 347 // Keys returns the list of keys associated with this event 348 func (evt *MissingParams) Keys() (sx Keys) { 349 return 350 } 351 352 // Keys returns the list of keys associated with this event 353 func (evt *Peer) Keys() (sx Keys) { 354 return 355 } 356 357 // Keys returns the list of keys associated with this event 358 func (evt *PeerStatusChange) Keys() (sx Keys) { 359 sx = append(sx, evt.Key(EndpointKey, endpointKeyID(evt.Endpoint.Technology, evt.Endpoint.Resource))) 360 return 361 } 362 363 // Keys returns the list of keys associated with this event 364 func (evt *PlaybackContinuing) Keys() (sx Keys) { 365 sx = append(sx, evt.Key(PlaybackKey, evt.Playback.ID)) 366 return 367 } 368 369 // Keys returns the list of keys associated with this event 370 func (evt *PlaybackFinished) Keys() (sx Keys) { 371 sx = append(sx, evt.Key(PlaybackKey, evt.Playback.ID)) 372 return 373 } 374 375 // Keys returns the list of keys associated with this event 376 func (evt *PlaybackStarted) Keys() (sx Keys) { 377 sx = append(sx, evt.Key(PlaybackKey, evt.Playback.ID)) 378 return 379 } 380 381 // Keys returns the list of keys associated with this event 382 func (evt *RecordingFailed) Keys() (sx Keys) { 383 sx = append(sx, evt.Key(LiveRecordingKey, evt.Recording.Name)) 384 return 385 } 386 387 // Keys returns the list of keys associated with this event 388 func (evt *RecordingFinished) Keys() (sx Keys) { 389 sx = append(sx, evt.Key(LiveRecordingKey, evt.Recording.Name)) 390 return 391 } 392 393 // Keys returns the list of keys associated with this event 394 func (evt *RecordingStarted) Keys() (sx Keys) { 395 sx = append(sx, evt.Key(LiveRecordingKey, evt.Recording.Name)) 396 return 397 } 398 399 // Keys returns the list of keys associated with this event 400 func (evt *StasisEnd) Keys() (sx Keys) { 401 sx = append(sx, evt.Key(ChannelKey, evt.Channel.ID)) 402 return 403 } 404 405 // Keys returns the list of keys associated with this event 406 func (evt *StasisStart) Keys() (sx Keys) { 407 sx = append(sx, evt.Key(ChannelKey, evt.Channel.ID)) 408 if evt.ReplaceChannel.ID != "" { 409 sx = append(sx, evt.Key(ChannelKey, evt.ReplaceChannel.ID)) 410 } 411 return 412 } 413 414 // Keys returns the list of keys associated with this event 415 func (evt *TextMessageReceived) Keys() (sx Keys) { 416 sx = append(sx, evt.Key(EndpointKey, endpointKeyID(evt.Endpoint.Technology, evt.Endpoint.Resource))) 417 return 418 } 419 420 // ---------- 421 422 // Created marks the BridgeCreated event that it created an event 423 func (evt *BridgeCreated) Created() (bridgeID string, related string) { 424 bridgeID = evt.Bridge.ID 425 if len(evt.Bridge.ChannelIDs) != 0 { 426 related = evt.Bridge.ChannelIDs[0] 427 } else { 428 related = evt.Bridge.Creator 429 } 430 return 431 } 432 433 // Destroyed returns the bridge that was finished by this event. 434 // Used by the proxy to route events to dialogs. 435 func (evt *BridgeDestroyed) Destroyed() string { 436 return evt.Bridge.ID 437 } 438 439 // GetChannelIDs gets the channel IDs for the event 440 func (evt *BridgeCreated) GetChannelIDs() (sx []string) { 441 sx = evt.Bridge.ChannelIDs 442 return 443 } 444 445 // GetBridgeIDs gets the bridge IDs for the event 446 func (evt *BridgeCreated) GetBridgeIDs() (sx []string) { 447 sx = append(sx, evt.Bridge.ID) 448 return 449 } 450 451 // GetBridgeIDs gets the bridge IDs for the event 452 func (evt *BridgeDestroyed) GetBridgeIDs() (sx []string) { 453 sx = append(sx, evt.Bridge.ID) 454 return 455 } 456 457 // GetBridgeIDs gets the bridge IDs for the event 458 func (evt *BridgeMerged) GetBridgeIDs() (sx []string) { 459 sx = append(sx, evt.Bridge.ID) 460 sx = append(sx, evt.BridgeFrom.ID) 461 return 462 } 463 464 // GetChannelIDs gets the channel IDs for the event 465 func (evt *ChannelCallerID) GetChannelIDs() (sx []string) { 466 sx = append(sx, evt.Channel.ID) 467 return 468 } 469 470 // GetChannelIDs gets the channel IDs for the event 471 func (evt *ChannelCreated) GetChannelIDs() (sx []string) { 472 sx = append(sx, evt.Channel.ID) 473 return 474 } 475 476 // GetChannelIDs gets the channel IDs for the event 477 func (evt *ChannelDialplan) GetChannelIDs() (sx []string) { 478 sx = append(sx, evt.Channel.ID) 479 return 480 } 481 482 // GetChannelIDs gets the channel IDs for the event 483 func (evt *ChannelDtmfReceived) GetChannelIDs() (sx []string) { 484 sx = append(sx, evt.Channel.ID) 485 return 486 } 487 488 // Created marks the event as creating a bridge for a channel and dialog 489 func (evt *ChannelEnteredBridge) Created() (o string, related string) { 490 o = evt.Bridge.ID 491 related = evt.Channel.ID 492 return 493 } 494 495 // GetChannelIDs gets the channel IDs for the event 496 func (evt *ChannelEnteredBridge) GetChannelIDs() (sx []string) { 497 sx = append(sx, evt.Channel.ID) 498 return 499 } 500 501 // GetBridgeIDs gets the bridge IDs for the event 502 func (evt *ChannelEnteredBridge) GetBridgeIDs() (sx []string) { 503 sx = append(sx, evt.Bridge.ID) 504 return 505 } 506 507 // GetChannelIDs gets the channel IDs for the event 508 func (evt *ChannelHangupRequest) GetChannelIDs() (sx []string) { 509 sx = append(sx, evt.Channel.ID) 510 return 511 } 512 513 // GetChannelIDs gets the channel IDs for the event 514 func (evt *ChannelHold) GetChannelIDs() (sx []string) { 515 sx = append(sx, evt.Channel.ID) 516 return 517 } 518 519 // GetChannelIDs gets the channel IDs for the event 520 func (evt *ChannelLeftBridge) GetChannelIDs() (sx []string) { 521 sx = append(sx, evt.Channel.ID) 522 return 523 } 524 525 // GetBridgeIDs gets the bridge IDs for the event 526 func (evt *ChannelLeftBridge) GetBridgeIDs() (sx []string) { 527 sx = append(sx, evt.Bridge.ID) 528 return 529 } 530 531 // GetChannelIDs gets the channel IDs for the event 532 func (evt *ChannelStateChange) GetChannelIDs() (sx []string) { 533 sx = append(sx, evt.Channel.ID) 534 return 535 } 536 537 // GetChannelIDs gets the channel IDs for the event 538 func (evt *ChannelTalkingStarted) GetChannelIDs() (sx []string) { 539 sx = append(sx, evt.Channel.ID) 540 return 541 } 542 543 // GetChannelIDs gets the channel IDs for the event 544 func (evt *ChannelUnhold) GetChannelIDs() (sx []string) { 545 sx = append(sx, evt.Channel.ID) 546 return 547 } 548 549 // GetChannelIDs gets the channel IDs for the event 550 func (evt *ChannelUserevent) GetChannelIDs() (sx []string) { 551 sx = append(sx, evt.Channel.ID) 552 return 553 } 554 555 // GetBridgeIDs gets the bridge IDs for the event 556 func (evt *ChannelUserevent) GetBridgeIDs() (sx []string) { 557 sx = append(sx, evt.Bridge.ID) 558 return 559 } 560 561 // GetEndpointIDs gets the bridge IDs for the event 562 func (evt *ChannelUserevent) GetEndpointIDs() (sx []string) { 563 sx = append(sx, evt.Endpoint.ID()) 564 return 565 } 566 567 // GetChannelIDs gets the channel IDs for the event 568 func (evt *ChannelVarset) GetChannelIDs() (sx []string) { 569 sx = append(sx, evt.Channel.ID) 570 return 571 } 572 573 // GetEndpointIDs gets the bridge IDs for the event 574 func (evt *ContactStatusChange) GetEndpointIDs() (sx []string) { 575 sx = append(sx, evt.Endpoint.ID()) 576 return 577 } 578 579 // GetChannelIDs gets the bridge IDs for the event 580 func (evt *Dial) GetChannelIDs() (sx []string) { 581 sx = append(sx, evt.Caller.ID) 582 if id := evt.Forwarded.ID; id != "" { 583 sx = append(sx, id) 584 } 585 if id := evt.Peer.ID; id != "" { 586 sx = append(sx, id) 587 } 588 589 return 590 } 591 592 // GetEndpointIDs gets the endpoint IDs for the event 593 func (evt *EndpointStateChange) GetEndpointIDs() (sx []string) { 594 sx = append(sx, evt.Endpoint.ID()) 595 return 596 } 597 598 // GetChannelIDs gets the channel IDs for the event 599 func (evt *EndpointStateChange) GetChannelIDs() (sx []string) { 600 sx = append(sx, evt.Endpoint.ChannelIDs...) 601 return 602 } 603 604 // GetEndpointIDs gets the endpoint IDs for the event 605 func (evt *PeerStatusChange) GetEndpointIDs() (sx []string) { 606 sx = append(sx, evt.Endpoint.ID()) 607 return 608 } 609 610 // GetPlaybackIDs gets the playback IDs for the event 611 func (evt *PlaybackContinuing) GetPlaybackIDs() (sx []string) { 612 sx = append(sx, evt.Playback.ID) 613 return 614 } 615 616 // GetChannelIDs gets the channel IDs for the event 617 func (evt *PlaybackContinuing) GetChannelIDs() (sx []string) { 618 s := resolveTarget("channel", evt.Playback.TargetURI) 619 if s == "" { 620 return 621 } 622 623 sx = append(sx, s) 624 return 625 } 626 627 // GetBridgeIDs gets the bridge IDs for the event 628 func (evt *PlaybackContinuing) GetBridgeIDs() (sx []string) { 629 s := resolveTarget("bridge", evt.Playback.TargetURI) 630 if s == "" { 631 return 632 } 633 sx = append(sx, s) 634 return 635 } 636 637 // GetPlaybackIDs gets the playback IDs for the event 638 func (evt *PlaybackFinished) GetPlaybackIDs() (sx []string) { 639 sx = append(sx, evt.Playback.ID) 640 return 641 } 642 643 // GetBridgeIDs gets the bridge IDs for the event 644 func (evt *PlaybackFinished) GetBridgeIDs() (sx []string) { 645 s := resolveTarget("bridge", evt.Playback.TargetURI) 646 if s == "" { 647 return 648 } 649 sx = append(sx, s) 650 return 651 } 652 653 // GetChannelIDs gets the channel IDs for the event 654 func (evt *PlaybackFinished) GetChannelIDs() (sx []string) { 655 s := resolveTarget("channel", evt.Playback.TargetURI) 656 if s == "" { 657 return 658 } 659 sx = append(sx, s) 660 return 661 } 662 663 // Destroyed returns the playbacK ID that was finished by this event. 664 // Used by the proxy to route events to dialogs. 665 func (evt *PlaybackFinished) Destroyed() (playbackID string) { 666 playbackID = evt.Playback.ID 667 return 668 } 669 670 // GetPlaybackIDs gets the playback IDs for the event 671 func (evt *PlaybackStarted) GetPlaybackIDs() (sx []string) { 672 sx = append(sx, evt.Playback.ID) 673 return 674 } 675 676 // GetChannelIDs gets the channel IDs for the event 677 func (evt *PlaybackStarted) GetChannelIDs() (sx []string) { 678 s := resolveTarget("channel", evt.Playback.TargetURI) 679 if s == "" { 680 return 681 } 682 sx = append(sx, s) 683 return 684 } 685 686 // GetBridgeIDs gets the bridge IDs for the event 687 func (evt *PlaybackStarted) GetBridgeIDs() (sx []string) { 688 s := resolveTarget("bridge", evt.Playback.TargetURI) 689 if s == "" { 690 return 691 } 692 sx = append(sx, s) 693 return 694 } 695 696 // Created returns the playbacK ID that we created plus the ID that the playback 697 // is operating on (a bridge or channel). 698 // Used by the proxy to route events to dialogs 699 func (evt *PlaybackStarted) Created() (playbackID, otherID string) { 700 playbackID = evt.Playback.ID 701 items := strings.Split(evt.Playback.TargetURI, ":") 702 if len(items) == 1 { 703 otherID = items[0] 704 } else { 705 otherID = items[1] 706 } 707 708 return 709 } 710 711 // Destroyed returns the item that gets destroyed by this event 712 func (evt *RecordingFailed) Destroyed() string { 713 return evt.Recording.ID() 714 } 715 716 // GetRecordingIDs gets the recording IDs for the event 717 func (evt *RecordingFailed) GetRecordingIDs() (sx []string) { 718 sx = append(sx, evt.Recording.ID()) 719 return 720 } 721 722 // GetChannelIDs gets the channel IDs for the event 723 func (evt *RecordingFailed) GetChannelIDs() (sx []string) { 724 s := resolveTarget("channel", evt.Recording.TargetURI) 725 if s == "" { 726 return 727 } 728 sx = append(sx, s) 729 return 730 } 731 732 // GetChannelIDs gets the channel IDs for the event 733 func (evt *RecordingStarted) GetChannelIDs() (sx []string) { 734 s := resolveTarget("channel", evt.Recording.TargetURI) 735 if s == "" { 736 return 737 } 738 sx = append(sx, s) 739 return 740 } 741 742 // GetChannelIDs gets the channel IDs for the event 743 func (evt *RecordingFinished) GetChannelIDs() (sx []string) { 744 s := resolveTarget("channel", evt.Recording.TargetURI) 745 if s == "" { 746 return 747 } 748 sx = append(sx, s) 749 return 750 } 751 752 // GetBridgeIDs gets the bridge IDs for the event 753 func (evt *RecordingFailed) GetBridgeIDs() (sx []string) { 754 s := resolveTarget("bridge", evt.Recording.TargetURI) 755 if s == "" { 756 return 757 } 758 sx = append(sx, s) 759 return 760 } 761 762 // GetBridgeIDs gets the bridge IDs for the event 763 func (evt *RecordingStarted) GetBridgeIDs() (sx []string) { 764 s := resolveTarget("bridge", evt.Recording.TargetURI) 765 if s == "" { 766 return 767 } 768 sx = append(sx, s) 769 return 770 } 771 772 // GetBridgeIDs gets the bridge IDs for the event 773 func (evt *RecordingFinished) GetBridgeIDs() (sx []string) { 774 s := resolveTarget("bridge", evt.Recording.TargetURI) 775 if s == "" { 776 return 777 } 778 sx = append(sx, s) 779 return 780 } 781 782 // GetRecordingIDs gets the recording IDs for the event 783 func (evt *RecordingFinished) GetRecordingIDs() (sx []string) { 784 sx = append(sx, evt.Recording.ID()) 785 return 786 } 787 788 // Destroyed returns the item that gets destroyed by this event 789 func (evt *RecordingFinished) Destroyed() string { 790 return evt.Recording.ID() 791 } 792 793 // GetRecordingIDs gets the recording IDs for the event 794 func (evt *RecordingStarted) GetRecordingIDs() (sx []string) { 795 sx = append(sx, evt.Recording.ID()) 796 return 797 } 798 799 // GetChannelIDs gets the channel IDs for the event 800 func (evt *StasisEnd) GetChannelIDs() (sx []string) { 801 sx = append(sx, evt.Channel.ID) 802 return 803 } 804 805 // GetChannelIDs gets the channel IDs for the event 806 func (evt *StasisStart) GetChannelIDs() (sx []string) { 807 sx = append(sx, evt.Channel.ID) 808 if id := evt.ReplaceChannel.ID; id != "" { 809 sx = append(sx, id) 810 } 811 return 812 } 813 814 // GetEndpointIDs gets the bridge IDs for the event 815 func (evt *TextMessageReceived) GetEndpointIDs() (sx []string) { 816 sx = append(sx, evt.Endpoint.ID()) 817 return 818 } 819 820 func resolveTarget(typ string, targetURI string) (s string) { 821 items := strings.Split(targetURI, ":") 822 if items[0] != typ { 823 return 824 } 825 if len(items) < 2 { 826 return 827 } 828 829 s = strings.Join(items[1:], ":") 830 return 831 832 } 833 834 // Header represents a set of key-value pairs to store transport-related metadata on Events 835 type Header map[string][]string 836 837 // Add appens the value to the list of values for the given header key. 838 func (h Header) Add(key, val string) { 839 h[key] = append(h[key], val) 840 } 841 842 // Set sets the value for the given header key, replacing any existing values. 843 func (h Header) Set(key, val string) { 844 h[key] = []string{val} 845 } 846 847 // Get returns the first value associated with the given header key. 848 func (h Header) Get(key string) string { 849 if h == nil { 850 return "" 851 } 852 853 v := h[key] 854 if len(v) == 0 { 855 return "" 856 } 857 return v[0] 858 } 859 860 // Del deletes the values associated with the given header key. 861 func (h Header) Del(key string) { 862 delete(h, key) 863 }