A wrapper for socket that implement a p2p connection with possibility of adding a cryptographic Layer
This class does not allow multiple clients
server
= socket listenerport
= port where the server listen tocipher
= transform stream to cipher messagesdecipher
= transform stream to decipher incoming messagesendPoint
= point where the clear messages can be read (it can be the socket itself, if no cryptographic layer was set)startPoint
= point where the clear messages can be written (it can be the socket itself, if no cryptographic layer was set)socket
= connection to another instance of this chat
connected
= true if a connection was established
key
= when a key is set, new cipher and decipher are created and piped in socket, so new messages are encrypted before they are sent, and decrypted when they come.
write(data, enc)
= write data into startPointconnect(options)
= connect this chat to a remote instance.disconnect()
= disconnect the chat if a connection is establishedsetCryptoLayer(cipher, decipher)
= wrap chat with a cryptographic layer.cipher
anddecipher
are Transform streams
connect
= triggered when a client was connectedbusy
= triggered when a connection is about to be established with a chat in progressclose
= triggered when a connection is closeddata
= triggered when a message arrives