{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies #-}
module Discord.Internal.Types.VoiceCommon where
import Control.Concurrent ( Chan, MVar, ThreadId )
import Control.Concurrent.BoundedChan qualified as Bounded
import Control.Exception.Safe ( Exception )
import Control.Lens ( makeFields )
import Control.Monad.Except
import Control.Monad.Reader
import Data.ByteString qualified as B
import Data.Text qualified as T
import Data.Word ( Word8 )
import GHC.Weak ( Weak )
import Network.Socket
import Network.WebSockets ( ConnectionException, Connection )
import Discord
import Discord.Types
import Discord.Internal.Gateway.EventLoop ( GatewayException(..) )
import Discord.Internal.Types.VoiceUDP
import Discord.Internal.Types.VoiceWebsocket
type Voice =
ReaderT DiscordBroadcastHandle (ExceptT VoiceError DiscordHandler)
data VoiceError
= VoiceNotAvailable
| NoServerAvailable
| InvalidPayloadOrder
deriving (Int -> VoiceError -> ShowS
[VoiceError] -> ShowS
VoiceError -> String
(Int -> VoiceError -> ShowS)
-> (VoiceError -> String)
-> ([VoiceError] -> ShowS)
-> Show VoiceError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [VoiceError] -> ShowS
$cshowList :: [VoiceError] -> ShowS
show :: VoiceError -> String
$cshow :: VoiceError -> String
showsPrec :: Int -> VoiceError -> ShowS
$cshowsPrec :: Int -> VoiceError -> ShowS
Show, VoiceError -> VoiceError -> Bool
(VoiceError -> VoiceError -> Bool)
-> (VoiceError -> VoiceError -> Bool) -> Eq VoiceError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: VoiceError -> VoiceError -> Bool
$c/= :: VoiceError -> VoiceError -> Bool
== :: VoiceError -> VoiceError -> Bool
$c== :: VoiceError -> VoiceError -> Bool
Eq)
data SubprocessException = SubprocessException String deriving (SubprocessException -> SubprocessException -> Bool
(SubprocessException -> SubprocessException -> Bool)
-> (SubprocessException -> SubprocessException -> Bool)
-> Eq SubprocessException
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SubprocessException -> SubprocessException -> Bool
$c/= :: SubprocessException -> SubprocessException -> Bool
== :: SubprocessException -> SubprocessException -> Bool
$c== :: SubprocessException -> SubprocessException -> Bool
Eq, Int -> SubprocessException -> ShowS
[SubprocessException] -> ShowS
SubprocessException -> String
(Int -> SubprocessException -> ShowS)
-> (SubprocessException -> String)
-> ([SubprocessException] -> ShowS)
-> Show SubprocessException
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SubprocessException] -> ShowS
$cshowList :: [SubprocessException] -> ShowS
show :: SubprocessException -> String
$cshow :: SubprocessException -> String
showsPrec :: Int -> SubprocessException -> ShowS
$cshowsPrec :: Int -> SubprocessException -> ShowS
Show)
instance Exception SubprocessException
data DiscordVoiceHandle = DiscordVoiceHandle
{ DiscordVoiceHandle -> GuildId
discordVoiceHandleGuildId :: GuildId
, DiscordVoiceHandle -> GuildId
discordVoiceHandleChannelId :: ChannelId
, DiscordVoiceHandle
-> (Weak ThreadId,
(VoiceWebsocketReceiveChan, VoiceWebsocketSendChan))
discordVoiceHandleWebsocket :: (Weak ThreadId, (VoiceWebsocketReceiveChan, VoiceWebsocketSendChan))
, DiscordVoiceHandle
-> (Weak ThreadId, (VoiceUDPReceiveChan, VoiceUDPSendChan))
discordVoiceHandleUdp :: (Weak ThreadId, (VoiceUDPReceiveChan, VoiceUDPSendChan))
, DiscordVoiceHandle -> Integer
discordVoiceHandleSsrc :: Integer
}
data DiscordBroadcastHandle = DiscordBroadcastHandle
{ DiscordBroadcastHandle -> MVar [DiscordVoiceHandle]
discordBroadcastHandleVoiceHandles :: MVar [DiscordVoiceHandle]
, DiscordBroadcastHandle -> MVar ()
discordBroadcastHandleMutEx :: MVar ()
}
data VoiceWebsocketException
= VoiceWebsocketCouldNotConnect T.Text
| VoiceWebsocketEventParseError T.Text
| VoiceWebsocketUnexpected VoiceWebsocketReceivable T.Text
| VoiceWebsocketConnection ConnectionException T.Text
deriving (Int -> VoiceWebsocketException -> ShowS
[VoiceWebsocketException] -> ShowS
VoiceWebsocketException -> String
(Int -> VoiceWebsocketException -> ShowS)
-> (VoiceWebsocketException -> String)
-> ([VoiceWebsocketException] -> ShowS)
-> Show VoiceWebsocketException
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [VoiceWebsocketException] -> ShowS
$cshowList :: [VoiceWebsocketException] -> ShowS
show :: VoiceWebsocketException -> String
$cshow :: VoiceWebsocketException -> String
showsPrec :: Int -> VoiceWebsocketException -> ShowS
$cshowsPrec :: Int -> VoiceWebsocketException -> ShowS
Show)
type VoiceWebsocketReceiveChan =
Chan (Either VoiceWebsocketException VoiceWebsocketReceivable)
type VoiceWebsocketSendChan = Chan VoiceWebsocketSendable
type VoiceUDPReceiveChan = Chan VoiceUDPPacket
type VoiceUDPSendChan = Bounded.BoundedChan B.ByteString
data WebsocketLaunchOpts = WebsocketLaunchOpts
{ WebsocketLaunchOpts -> GuildId
websocketLaunchOptsBotUserId :: UserId
, WebsocketLaunchOpts -> Text
websocketLaunchOptsSessionId :: T.Text
, WebsocketLaunchOpts -> Text
websocketLaunchOptsToken :: T.Text
, WebsocketLaunchOpts -> GuildId
websocketLaunchOptsGuildId :: GuildId
, WebsocketLaunchOpts -> Text
websocketLaunchOptsEndpoint :: T.Text
, WebsocketLaunchOpts -> Chan (Either GatewayException Event)
websocketLaunchOptsGatewayEvents :: Chan (Either GatewayException Event)
, WebsocketLaunchOpts
-> (VoiceWebsocketReceiveChan, VoiceWebsocketSendChan)
websocketLaunchOptsWsHandle :: (VoiceWebsocketReceiveChan, VoiceWebsocketSendChan)
, WebsocketLaunchOpts -> MVar (Weak ThreadId)
websocketLaunchOptsUdpTid :: MVar (Weak ThreadId)
, WebsocketLaunchOpts -> (VoiceUDPReceiveChan, VoiceUDPSendChan)
websocketLaunchOptsUdpHandle :: (VoiceUDPReceiveChan, VoiceUDPSendChan)
, WebsocketLaunchOpts -> MVar Integer
websocketLaunchOptsSsrc :: MVar Integer
}
data WebsocketConn = WebsocketConn
{ WebsocketConn -> Connection
websocketConnConnection :: Connection
, WebsocketConn -> WebsocketLaunchOpts
websocketConnLaunchOpts :: WebsocketLaunchOpts
}
data UDPLaunchOpts = UDPLaunchOpts
{ UDPLaunchOpts -> Integer
uDPLaunchOptsSsrc :: Integer
, UDPLaunchOpts -> Text
uDPLaunchOptsIp :: T.Text
, UDPLaunchOpts -> Integer
uDPLaunchOptsPort :: Integer
, UDPLaunchOpts -> Text
uDPLaunchOptsMode :: T.Text
, UDPLaunchOpts -> (VoiceUDPReceiveChan, VoiceUDPSendChan)
uDPLaunchOptsUdpHandle :: (VoiceUDPReceiveChan, VoiceUDPSendChan)
, UDPLaunchOpts -> MVar [Word8]
uDPLaunchOptsSecretKey :: MVar [Word8]
}
data UDPConn = UDPConn
{ UDPConn -> UDPLaunchOpts
uDPConnLaunchOpts :: UDPLaunchOpts
, UDPConn -> Socket
uDPConnSocket :: Socket
}
$(makeFields ''DiscordVoiceHandle)
$(makeFields ''DiscordBroadcastHandle)
$(makeFields ''WebsocketLaunchOpts)
$(makeFields ''WebsocketConn)
$(makeFields ''UDPLaunchOpts)
$(makeFields ''UDPConn)