-- | Wrapper for supporting multiple protocol versions{-# LANGUAGE ExistentialQuantification #-}moduleNetwork.WebSockets.Protocol(Protocol(..),TextProtocol,BinaryProtocol,close,ping,pong,textData,binaryData)whereimportBlaze.ByteString.Builder(Builder)importSystem.Random(RandomGen)importqualifiedData.ByteStringasBimportqualifiedData.EnumeratorasEimportNetwork.WebSockets.TypesimportNetwork.WebSockets.Handshake.HttpimportqualifiedNetwork.WebSockets.Protocol.UnsafeasUnsafeclassProtocolpwhere-- | Unique identifier for us.version::p->String-- | Version accepted in the "Sec-WebSocket-Version " header. This is-- usually not the same, or derivable from "version", e.g. for hybi10, it's-- "7", "8" or "17".headerVersions::p->[B.ByteString]-- | Determine if the protocol is compatible with a requested version. A-- default implementation exists which uses the @headerVersions@ of the-- protocol.supported::p->RequestHttpPart->Boolsupportedph=casegetSecWebSocketVersionhofJustv->v`elem`headerVersionsp_->False-- | Encodes messages to binary 'Builder's. Takes a random source so it is-- able to do masking of frames (needed in some cases).encodeMessages::(Monadm,RandomGeng)=>p-- ^ Protocol->Bool-- ^ Mask messages->g-- ^ Random source->E.Enumeratee(Messagep)Builderma-- | Decodes messages from binary 'B.ByteString's.decodeMessages::Monadm=>p->E.EnumerateeB.ByteString(Messagep)ma-- | Create a @Request@ that can be sent to the websockets server to open-- the connection.createRequest::p->B.ByteString-- ^ Hostname of the server.->B.ByteString-- ^ Path->MaybeB.ByteString-- ^ Origin where we are connecting from.->Maybe[B.ByteString]-- ^ Protocols list.->Bool-- ^ Is the connection secure, i.e. wss.->IORequestHttpPart-- ^ HTTP request that can be sent to the-- to the server to initiate the connection.-- | Parse and validate the rest of the request. For hybi10, this is just-- validation, but hybi00 also needs to fetch a "security token"---- In case of failure, this function may throw a 'HandshakeError'.-- be amended with the RequestHttpPart for the user)finishRequest::Monadm=>p->RequestHttpPart->E.IterateeB.ByteStringmRequest-- | Parse and validate the handshake response received from the server.finishResponse::Monadm=>p->RequestHttpPart->ResponseHttpPart->E.IterateeB.ByteStringmResponseBody-- | Implementations of the specificationimplementations::[p]classProtocolp=>TextProtocolpclassTextProtocolp=>BinaryProtocolp-- | Construct a close messageclose::(TextProtocolp,WebSocketsDataa)=>a->Messagepclose=Unsafe.close-- | Construct a ping messageping::(BinaryProtocolp,WebSocketsDataa)=>a->Messagepping=Unsafe.ping-- | Construct a pong messagepong::(BinaryProtocolp,WebSocketsDataa)=>a->Messageppong=Unsafe.pong-- | Construct a text messagetextData::(TextProtocolp,WebSocketsDataa)=>a->MessageptextData=Unsafe.textData-- | Construct a binary messagebinaryData::(BinaryProtocolp,WebSocketsDataa)=>a->MessagepbinaryData=Unsafe.binaryData