gomble

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2020 License: MIT Imports: 16 Imported by: 0

README

  • audiohandler.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/audiohandler.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.

Documentation

Index

Constants

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

constants for audiotypes of mumble

View Source
const (
	// Track got interrupted by user
	TRACK_INTERRUPTED = iota
	// Track ended playing because Track was over
	TRACK_ENDED
	// Some other failure occurred. The Logs should be checked for further Information
	TRACK_OTHER
)

Variables

View Source
var Listener listener

Functions

func Begin

func Begin()

Initializes the Connection

func GetUser

func GetUser(userid uint32) *user

func Init

func Init(loglevel logger.Loglevel, address string)

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 Play

func Play(track audiosources.Audiosource, interrupt bool) bool

param track The track to start playing, passing nil and interrupt true will stop the current track and return false param interrupt Whether to only start if nothing else is playing, passing an audiosource and interrupt false (and a audiotrack is currently playing) will return false and not start the track return True if the track was started

func Stop

func Stop()

Stops the current Track if one is playing

func WriteInt16InFile

func WriteInt16InFile(path string, buffer []int16)

write int16 buffer in file of path with offset

Types

type Audiohandler

type Audiohandler struct {
	// contains filtered or unexported fields
}

type Channel

type Channel struct {
	// contains filtered or unexported fields
}

func GetChannel

func GetChannel(channelid uint32) Channel

func (Channel) SendMessage

func (c Channel) SendMessage(msg string)

send Message to the user

type ChannelMessageReceivedEvent

type ChannelMessageReceivedEvent struct {
	Actor   uint32
	Channel uint32
	Message string
}

type PrivateMessageReceivedEvent

type PrivateMessageReceivedEvent struct {
	Actor   uint32
	Message string
}

type TrackEndedEvent

type TrackEndedEvent struct {
	Track  audiosources.Audiosource
	Reason TrackEndedReason
}

type TrackEndedReason

type TrackEndedReason int

Reasons why track ended playing

Directories

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

Jump to

Keyboard shortcuts

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