some comment grammar fixes? need help here.

Former-commit-id: 5695e4c6456b052fae45de1fa6724fae39ceac3e
This commit is contained in:
Gerasimos (Makis) Maropoulos 2017-12-27 17:09:47 +02:00
parent 685954d341
commit 969aaab4f6
4 changed files with 62 additions and 48 deletions

View File

@ -45,8 +45,11 @@ type Config struct {
// The request is an argument which you can use to generate the ID (from headers for example). // The request is an argument which you can use to generate the ID (from headers for example).
// If empty then the ID is generated by DefaultIDGenerator: randomString(64) // If empty then the ID is generated by DefaultIDGenerator: randomString(64)
IDGenerator func(ctx context.Context) string IDGenerator func(ctx context.Context) string
// Error is the function that will be fired if any client couldn't upgrade the HTTP connection
// to a websocket connection, a handshake error.
Error func(w http.ResponseWriter, r *http.Request, status int, reason error) Error func(w http.ResponseWriter, r *http.Request, status int, reason error)
// CheckOrigin a function that is called right before the handshake,
// if returns false then that client is not allowed to connect with the websocket server.
CheckOrigin func(r *http.Request) bool CheckOrigin func(r *http.Request) bool
// HandshakeTimeout specifies the duration for the handshake to complete. // HandshakeTimeout specifies the duration for the handshake to complete.
HandshakeTimeout time.Duration HandshakeTimeout time.Duration

View File

@ -1,7 +1,14 @@
<!-- the message's input -->
<input id="input" type="text" /> <input id="input" type="text" />
<!-- when clicked then an iris websocket event will be sent to the server, at this example we registered the 'chat' -->
<button onclick="send()">Send</button> <button onclick="send()">Send</button>
<!-- the messages will be shown here -->
<pre id="output"></pre> <pre id="output"></pre>
<!-- import the iris client-side library for browser-->
<script src="/iris-ws.js"></script> <script src="/iris-ws.js"></script>
<script> <script>
var scheme = document.location.protocol == "https:" ? "wss" : "ws"; var scheme = document.location.protocol == "https:" ? "wss" : "ws";
var port = document.location.port ? (":" + document.location.port) : ""; var port = document.location.port ? (":" + document.location.port) : "";
@ -23,11 +30,11 @@
// read events from the server // read events from the server
socket.On("chat", function (msg) { socket.On("chat", function (msg) {
addMessage(msg) addMessage(msg);
}); });
function send() { function send() {
addMessage("Me: " + input.value) // write ourselves addMessage("Me: " + input.value); // write ourselves
socket.Emit("chat", input.value);// send chat event data to the websocket server socket.Emit("chat", input.value);// send chat event data to the websocket server
input.value = ""; // clear the input input.value = ""; // clear the input
} }
@ -35,5 +42,4 @@
function addMessage(msg) { function addMessage(msg) {
output.innerHTML += msg + "\n"; output.innerHTML += msg + "\n";
} }
</script> </script>

View File

@ -41,8 +41,11 @@ type Config struct {
// The request is an argument which you can use to generate the ID (from headers for example). // The request is an argument which you can use to generate the ID (from headers for example).
// If empty then the ID is generated by DefaultIDGenerator: randomString(64) // If empty then the ID is generated by DefaultIDGenerator: randomString(64)
IDGenerator func(ctx context.Context) string IDGenerator func(ctx context.Context) string
// Error is the function that will be fired if any client couldn't upgrade the HTTP connection
// to a websocket connection, a handshake error.
Error func(w http.ResponseWriter, r *http.Request, status int, reason error) Error func(w http.ResponseWriter, r *http.Request, status int, reason error)
// CheckOrigin a function that is called right before the handshake,
// if returns false then that client is not allowed to connect with the websocket server.
CheckOrigin func(r *http.Request) bool CheckOrigin func(r *http.Request) bool
// HandshakeTimeout specifies the duration for the handshake to complete. // HandshakeTimeout specifies the duration for the handshake to complete.
HandshakeTimeout time.Duration HandshakeTimeout time.Duration
@ -57,7 +60,7 @@ type Config struct {
// PongTimeout allowed to read the next pong message from the connection. // PongTimeout allowed to read the next pong message from the connection.
// Default value is 60 * time.Second // Default value is 60 * time.Second
PongTimeout time.Duration PongTimeout time.Duration
// PingPeriod send ping messages to the connection with this period. Must be less than PongTimeout. // PingPeriod send ping messages to the connection within this period. Must be less than PongTimeout.
// Default value is 60 *time.Second // Default value is 60 *time.Second
PingPeriod time.Duration PingPeriod time.Duration
// MaxMessageSize max message size allowed from connection. // MaxMessageSize max message size allowed from connection.
@ -65,18 +68,20 @@ type Config struct {
MaxMessageSize int64 MaxMessageSize int64
// BinaryMessages set it to true in order to denotes binary data messages instead of utf-8 text // BinaryMessages set it to true in order to denotes binary data messages instead of utf-8 text
// compatible if you wanna use the Connection's EmitMessage to send a custom binary data to the client, like a native server-client communication. // compatible if you wanna use the Connection's EmitMessage to send a custom binary data to the client, like a native server-client communication.
// defaults to false // Default value is false
BinaryMessages bool BinaryMessages bool
// ReadBufferSize is the buffer size for the underline reader // ReadBufferSize is the buffer size for the connection reader.
// Default value is 4096 // Default value is 4096
ReadBufferSize int ReadBufferSize int
// WriteBufferSize is the buffer size for the underline writer // WriteBufferSize is the buffer size for the connection writer.
// Default value is 4096 // Default value is 4096
WriteBufferSize int WriteBufferSize int
// EnableCompression specify if the server should attempt to negotiate per // EnableCompression specify if the server should attempt to negotiate per
// message compression (RFC 7692). Setting this value to true does not // message compression (RFC 7692). Setting this value to true does not
// guarantee that compression will be supported. Currently only "no context // guarantee that compression will be supported. Currently only "no context
// takeover" modes are supported. // takeover" modes are supported.
//
// Defauls to false and it should be remain as it is, unless special requirements.
EnableCompression bool EnableCompression bool
// Subprotocols specifies the server's supported protocols in order of // Subprotocols specifies the server's supported protocols in order of

View File

@ -67,8 +67,8 @@ func (r *ConnectionValues) Reset() {
*r = (*r)[:0] *r = (*r)[:0]
} }
// UnderlineConnection is used for compatible with fasthttp and net/http underline websocket libraries // UnderlineConnection is the underline connection, nothing to think about,
// we only need ~8 funcs from websocket.Conn so: // it's used internally mostly but can be used for extreme cases with other libraries.
type UnderlineConnection interface { type UnderlineConnection interface {
// SetWriteDeadline sets the write deadline on the underlying network // SetWriteDeadline sets the write deadline on the underlying network
// connection. After a write has timed out, the websocket state is corrupt and // connection. After a write has timed out, the websocket state is corrupt and
@ -118,13 +118,13 @@ type UnderlineConnection interface {
// ------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------
type ( type (
// DisconnectFunc is the callback which fires when a client/connection closed // DisconnectFunc is the callback which is fired when a client/connection closed
DisconnectFunc func() DisconnectFunc func()
// LeaveRoomFunc is the callback which fires when a client/connection leaves from any room. // LeaveRoomFunc is the callback which is fired when a client/connection leaves from any room.
// This is called automatically when client/connection disconnected // This is called automatically when client/connection disconnected
// (because websocket server automatically leaves from all joined rooms) // (because websocket server automatically leaves from all joined rooms)
LeaveRoomFunc func(roomName string) LeaveRoomFunc func(roomName string)
// ErrorFunc is the callback which fires when an error happens // ErrorFunc is the callback which fires whenever an error occurs
ErrorFunc (func(string)) ErrorFunc (func(string))
// NativeMessageFunc is the callback for native websocket messages, receives one []byte parameter which is the raw client's message // NativeMessageFunc is the callback for native websocket messages, receives one []byte parameter which is the raw client's message
NativeMessageFunc func([]byte) NativeMessageFunc func([]byte)
@ -155,26 +155,26 @@ type (
// then you use it to receive user information, for example: from headers // then you use it to receive user information, for example: from headers
Context() context.Context Context() context.Context
// OnDisconnect registers a callback which fires when this connection is closed by an error or manual // OnDisconnect registers a callback which is fired when this connection is closed by an error or manual
OnDisconnect(DisconnectFunc) OnDisconnect(DisconnectFunc)
// OnError registers a callback which fires when this connection occurs an error // OnError registers a callback which fires when this connection occurs an error
OnError(ErrorFunc) OnError(ErrorFunc)
// OnPing registers a callback which fires on each ping // OnPing registers a callback which fires on each ping
OnPing(PingFunc) OnPing(PingFunc)
// FireStatusCode can be used to send a custom error message to the connection // FireOnError can be used to send a custom error message to the connection
// //
// It does nothing more than firing the OnError listeners. It doesn't sends anything to the client. // It does nothing more than firing the OnError listeners. It doesn't send anything to the client.
FireOnError(errorMessage string) FireOnError(errorMessage string)
// To defines where server should send a message // To defines on what "room" (see Join) the server should send a message
// returns an emitter to send messages // returns an Emmiter(`EmitMessage` & `Emit`) to send messages.
To(string) Emitter To(string) Emitter
// OnMessage registers a callback which fires when native websocket message received // OnMessage registers a callback which fires when native websocket message received
OnMessage(NativeMessageFunc) OnMessage(NativeMessageFunc)
// On registers a callback to a particular event which fires when a message to this event received // On registers a callback to a particular event which is fired when a message to this event is received
On(string, MessageFunc) On(string, MessageFunc)
// Join join a connection to a room, it doesn't check if connection is already there, so care // Join registers this connection to a room, if it doesn't exist then it creates a new. One room can have one or more connections. One connection can be joined to many rooms. All connections are joined to a room specified by their `ID` automatically.
Join(string) Join(string)
// Leave removes a connection from a room // Leave removes this connection entry from a room
// Returns true if the connection has actually left from the particular room. // Returns true if the connection has actually left from the particular room.
Leave(string) bool Leave(string) bool
// OnLeave registers a callback which fires when this connection left from any joined room. // OnLeave registers a callback which fires when this connection left from any joined room.