gomble

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2021 License: MIT Imports: 18 Imported by: 0

README

  • track.go is responsible for starting and stopping an audiosource/audiotrack (defined in audiosources/audiosource.go). The Play function starts a new go routine which takes the audio from the audiosource, encodes in opus and sends it to the Server.
  • audiopackagereader.go is currently not in use (since I don't see any reason to receive audio at the moment)
  • audiopackagewriter.go has only 1 function which is responsible for sending an audiopackage to the server according to the mumble protocol. It also decides whether to send the audio over tcp or udp (which is decided by the audiocryptoconf tcptunnelmode attribute)
  • channel.go can be used to send a Message to a specified channel. For that you first need to get the specified channel via GetChannel() and then use that channel to send a message to it: channel.GetChannel("MSG")
  • event.go defines all event structs. Furthermore it defines constants related to these events
  • eventhandler.go consists of the Init(), Begin() and eventRoutine() functions. Init() sets some settings like the loglevel or the ip address of the mumble server to join. Begin() should be at the end of your main function because it starts the main event-loop eventRoutine() and is therefore blocking. Here you can also find the Listener variable which can be used by the client program to attach callback functions like OnChannelMessageReceived or OnTrackEnded.
  • packagereader.go is responsible for reading packages. the readRoutine() function is just a loop for receiving packages from the server. It therefore generates events with the information it got from the packages and sends this event to the eventRoutine() in eventhandler.go
  • packagewriter.go is the source file which each other source file uses to send stuff the mumble server. writeProto() and sendPacket() are used to send protobuff messages to the server and the pingRoutine() is responsible for sending ping packages to the mumble server every few seconds. the pingRoutine() function sends two different pings to the mumble-server. One Ping over TCP, because we need to ping the mumble-server every 30 seconds, otherwise the mumble-server will kick us. And the other Ping over UDP in order to check if the UDP "connection" to the mumble server is still working. If not we will send our audio data over TCP to the server.
  • user.go can be used to send a Message to a specified user. For that you first need to get the specified user via GetUser() and then use that user to send a message to it: user.GetUser("MSG")
  • util.go contains only a few methods I used for debugging
  • varint.go consists of some encoding used by the mumble protocol

To understand how all these components work behind the scene, a little example:
Say for instance we connect to a mumble server and everytime someone types in #test, we want to play a specific youtube video. Assuming we already configured the callbacks Receiving messages, we first need to load a new youtubevideo by calling NewYoutubeVideo() in gomble/audiosources/youtube/youtube.go, which does all the stuff it needs to, to download the youtubevideo. After that the NewYoutubeVideo() function returns a youtubevideo struct, which we can use as argument for the Play() function in gomble/track.go. The Play() function starts the audioroutine() which takes the audiodata of the audiosource/track encodes it in opus and sends it to the server in a loop until the audiosource/track is done. To get the audiodata the youtubevideo downloads the youtubevideo and Because the youtubevideo is just an webm container youtube.go uses the gomble/container/matroska/matroska.go to decode the webm/matroska container. After that youtube.go uses the gomble/audioformats/opus.go to decode the opus audiodata which we got from the container. After that youtube.go returns the raw pcm audio data back to the audioroutine in gomble/audiohandler.go.
To encode the audiodata in opus, the gomble/audiohandler.go uses the gomble/audioformats/opus.go to encode the raw pcm audio data it got from the audiosource/track youtube.go. After that it uses the sendAudioPacket() function in gomble/audiopackagewriter.go to send the opus encoded audio data to the mumble server. Here a little illustration:

alt text

Documentation

Index

Constants

View Source
const (
	CELTAplha = iota
	Ping
	Speex
	CELTBeta
	OPUS
)

constants for audiotypes of mumble

View Source
const (
	TRACK_TYPE_YOUTUBE = iota
	TRACK_TYPE_OGGFILE
)

Variables

View Source
var Listener listener

Functions

func Begin

func Begin()

Initializes the Connection

func Init

func Init(loglevel logger.Loglevel, address string, forceTcpTunnelMode bool)

Initializes some settings for gomble and returns an Eventhandler which can be used to add event-listeners loglevel the loglevel to use e.g. logger.DEBUG, logger.INFO, logger.WARN, logger.ERROR, logger.FATAL addr the address of the mumble-server written like "192.168.178.150:64738"

func Pause added in v0.2.0

func Pause()

Pauses the current Track if one is playing

func Play

func Play(t *Track) bool

func Resume added in v0.2.0

func Resume()

func SendMessageToChannel added in v0.4.0

func SendMessageToChannel(msg string, channelid uint32)

send Message to the user

func SendMessageToUser added in v0.4.0

func SendMessageToUser(msg string, userid uint32)

send Message to the user

func Stop

func Stop()

Stops the current Track if one is playing

func SwitchChannel added in v0.4.0

func SwitchChannel(channelid uint32)

func WriteInt16InFile

func WriteInt16InFile(path string, buffer []int16)

write int16 buffer in file of path with offset

Types

type ChannelMessageReceivedEvent

type ChannelMessageReceivedEvent struct {
	Actor   uint32
	Channel uint32
	Message string
}

type PrivateMessageReceivedEvent

type PrivateMessageReceivedEvent struct {
	Actor   uint32
	Message string
}

type Track added in v0.2.0

type Track struct {

	// Never ever change that outside of this source file
	Done bool
	// contains filtered or unexported fields
}

func GetCurrentTrack added in v0.2.0

func GetCurrentTrack() *Track

func LoadTrack added in v0.2.0

func LoadTrack(url string) (*Track, error)

func (*Track) GetTitle added in v0.2.0

func (t *Track) GetTitle() string

type TrackExceptionEvent added in v0.2.0

type TrackExceptionEvent struct {
	Track *Track
	// contains filtered or unexported fields
}

Some other failure occurred. The Logs should be checked for further Information

type TrackFinishedEvent added in v0.2.0

type TrackFinishedEvent struct {
	Track *Track
}

Track Finished playing

type TrackPausedEvent added in v0.2.0

type TrackPausedEvent struct {
	Track *Track
}

Track got paused

type TrackStoppedEvent added in v0.2.0

type TrackStoppedEvent struct {
	Track *Track
}

Track got interrupted/stopped by user

type UserState added in v0.4.0

type UserState struct {
	Name      string
	Session   uint32
	ChannelId uint32
}
var BotUserState UserState

Directories

Path Synopsis
go wrapper for c opus library.
go wrapper for c opus library.
container

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL