-
-
Save Palmik/2956244 to your computer and use it in GitHub Desktop.
_
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | You can follow the progress here: https://github.com/Palmik/wai-sockjs/ | |
import Control.Monad.IO.Class | |
import Control.Concurrent.MVar.Lifted | |
import Data.Conduit | |
import Data.Proxy | |
import qualified Data.HashMap.Strict as HM | |
import qualified Data.Text as T | |
import qualified Data.ByteString as B | |
import qualified Network.Wai as W | |
------------------------------------------------------------------------------ | |
-- | Application (server application, such as the example echo) related stuff | |
type Application m = Source m B.ByteString -- ^ Source for incoming messages (_ => Application) | |
-> Sink B.ByteString m () -- ^ Sink for outgoing messages (Application => _) | |
-> m () | |
------------------------------------------------------------------------------ | |
-- | Session related stuff | |
type SessionID = T.Text | |
-- | Session contains all the neccessary timers, buffers (downstream and upstream), status flags, etc. | |
-- Session should also be tagged by specific transport. | |
data Session = Session | |
newtype Environment = Environment { unEnvironment :: MVar (HM.HashMap SessionID (MVar Session)) } | |
newSession :: MonadBase IO m | |
=> SessionID | |
-> m Session | |
newSession = undefined | |
addSession :: MonadBaseControl IO m | |
=> SessionID | |
-> Session | |
-> Environment | |
-> m () | |
addSession = undefined | |
modifySession :: MonadBaseControl IO m | |
=> (Session -> Session) | |
-> SessionID | |
-> Environment | |
-> m () | |
modifySession = undefined | |
-- | Retrieves session with the given ID (if there is no such session, it's created first) | |
getSession :: MonadBaseControl IO m | |
=> SessionID | |
-> Environmnet | |
-> MVar Session | |
getSession = undefined | |
------------------------------------------------------------------------------ | |
-- | Frame related stuff | |
data Frame = Frame -- nothing unusual here | |
------------------------------------------------------------------------------ | |
-- | Transport related stuff | |
class Transport tag where | |
-- | Used for _ => Application communication. | |
-- The request is checked whether it conforms the transport's rules and is then saved to a buffer. | |
-- The '_' could stand for e.g. some web app communication with out server Application | |
handleIncoming :: MonadBaseControl IO m | |
=> Proxy tag | |
-> Evironment -- Or we could use simply Session, if it turns out, that we can handle session creation globally. | |
-> W.Request | |
-> m () | |
-- | Used for Application => _ communication | |
-- The frame is checked whether it conforms the transport's rules and is then send (no buffering here). | |
-- The '_' could stand for e.g. some web app communication with out server Application | |
send :: MonadBaseControl IO m | |
=> Proxy tag | |
-> Frame | |
-> m () | |
------------------------------------------------------------------------------ | |
-- | Handler related stuff | |
-- | Internally uses Transport's send (potentially hidden behind some intermediate buffer). | |
sessionSink :: MonadBaseControl IO m | |
=> Session | |
-> Sink B.ByteString m () | |
sessionSink = undefined | |
-- | Internally uses the Session's buffer (which was written into by Transport's handleIncoming) | |
sessionSource :: MonadBaseControl IO m | |
=> Session | |
-> Source m B.ByteString | |
sessionSource = undefined | |
runApplication :: MonadBaseControl IO m | |
=> Application m | |
-> Session | |
-> m () | |
runApplication = undefined | |
-- | |
main = undefined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment