Skip to content

Commit

Permalink
add ability to set voice target
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Cooper committed Dec 4, 2014
1 parent 4ab42bc commit a147fc5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion gumble/audio.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ func (ab AudioBuffer) writeTo(client *Client, w io.Writer) (int64, error) {

// Create audio header
var header bytes.Buffer
formatTarget := byte(4)<<5 | byte(0)
var targetId int
if target := client.audioTarget; target != nil {
targetId = target.id
}
formatTarget := byte(4)<<5 | byte(targetId)
if err := header.WriteByte(formatTarget); err != nil {
return 0, err
}
Expand Down
8 changes: 8 additions & 0 deletions gumble/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type Client struct {

audioEncoder *gopus.Encoder
audioSequence int
audioTarget *VoiceTarget

end chan bool
closeMutex sync.Mutex
Expand Down Expand Up @@ -102,6 +103,7 @@ func (c *Client) Connect() error {
encoder.SetVbr(false)
c.audioEncoder = encoder
c.audioSequence = 0
c.audioTarget = nil
}
if conn, err := tls.DialWithDialer(&c.config.Dialer, "tcp", c.config.Address, &c.config.TlsConfig); err != nil {
c.audioEncoder = nil
Expand Down Expand Up @@ -292,6 +294,12 @@ func (c *Client) ContextActions() ContextActions {
return c.contextActions
}

// SetVoiceTarget sets to whom transmitted audio will be sent. The VoiceTarget
// must have already been sent to the server for targeting to work correctly.
func (c *Client) SetVoiceTarget(target *VoiceTarget) {
c.audioTarget = target
}

// Send will send a message to the server.
func (c *Client) Send(message Message) error {
c.sendMutex.Lock()
Expand Down

0 comments on commit a147fc5

Please sign in to comment.