github.com/CyCoreSystems/ari@v4.8.4+incompatible/client/native/playback.go (about)

     1  package native
     2  
     3  import (
     4  	"errors"
     5  
     6  	"github.com/CyCoreSystems/ari"
     7  )
     8  
     9  // Playback provides the ARI Playback accessors for the native client
    10  type Playback struct {
    11  	client *Client
    12  }
    13  
    14  // Get gets a lazy handle for the given playback identifier
    15  func (a *Playback) Get(key *ari.Key) *ari.PlaybackHandle {
    16  	return ari.NewPlaybackHandle(a.client.stamp(key), a, nil)
    17  }
    18  
    19  // Data returns a playback's details.
    20  // (Equivalent to GET /playbacks/{playbackID})
    21  func (a *Playback) Data(key *ari.Key) (*ari.PlaybackData, error) {
    22  	if key == nil || key.ID == "" {
    23  		return nil, errors.New("playback key not supplied")
    24  	}
    25  
    26  	var data = new(ari.PlaybackData)
    27  	if err := a.client.get("/playbacks/"+key.ID, data); err != nil {
    28  		return nil, dataGetError(err, "playback", "%v", key.ID)
    29  	}
    30  
    31  	data.Key = a.client.stamp(key)
    32  	return data, nil
    33  }
    34  
    35  // Control performs the given operation on the current playback.  Available operations are:
    36  //   - restart
    37  //   - pause
    38  //   - unpause
    39  //   - reverse
    40  //   - forward
    41  func (a *Playback) Control(key *ari.Key, op string) error {
    42  	req := struct {
    43  		Operation string `json:"operation"`
    44  	}{
    45  		Operation: op,
    46  	}
    47  	return a.client.post("/playbacks/"+key.ID+"/control", nil, &req)
    48  }
    49  
    50  // Stop stops a playback session.
    51  // (Equivalent to DELETE /playbacks/{playbackID})
    52  func (a *Playback) Stop(key *ari.Key) error {
    53  	return a.client.del("/playbacks/"+key.ID, nil, "")
    54  }
    55  
    56  // Subscribe listens for ARI events for the given playback entity
    57  func (a *Playback) Subscribe(key *ari.Key, n ...string) ari.Subscription {
    58  	return a.client.Bus().Subscribe(key, n...)
    59  }