mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-13 07:29:30 +01:00
6a69a65860
Currently working with a mini irc js implem, the flow: * PASS * NICK * USER * JOIN * PRIVMSG works and the ping/pong timeout keep the communication open.
57 lines
1.1 KiB
Go
57 lines
1.1 KiB
Go
package irc
|
|
|
|
import (
|
|
"github.com/gorilla/websocket"
|
|
"net"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
var upgrader = websocket.Upgrader{
|
|
ReadBufferSize: 1024,
|
|
WriteBufferSize: 1024,
|
|
CheckOrigin: func(r *http.Request) bool { return true },
|
|
}
|
|
|
|
type WSContainer struct {
|
|
conn *websocket.Conn
|
|
}
|
|
|
|
func (this WSContainer) Close() error {
|
|
return this.conn.Close()
|
|
}
|
|
|
|
func (this WSContainer) LocalAddr() net.Addr {
|
|
return this.conn.LocalAddr()
|
|
}
|
|
|
|
func (this WSContainer) RemoteAddr() net.Addr {
|
|
return this.conn.RemoteAddr()
|
|
}
|
|
|
|
func (this WSContainer) Read(msg []byte) (int, error) {
|
|
_, tmp, err := this.conn.ReadMessage()
|
|
str := (string)(tmp)
|
|
n := copy(msg, ([]byte)(str+CRLF+CRLF))
|
|
return n, err
|
|
}
|
|
|
|
func (this WSContainer) Write(msg []byte) (int, error) {
|
|
err := this.conn.WriteMessage(1, msg)
|
|
return len(msg), err
|
|
}
|
|
|
|
func (this WSContainer) SetDeadline(t time.Time) error {
|
|
err := this.conn.SetWriteDeadline(t)
|
|
err = this.conn.SetReadDeadline(t)
|
|
return err
|
|
}
|
|
|
|
func (this WSContainer) SetReadDeadline(t time.Time) error {
|
|
return this.conn.SetReadDeadline(t)
|
|
}
|
|
|
|
func (this WSContainer) SetWriteDeadline(t time.Time) error {
|
|
return this.conn.SetWriteDeadline(t)
|
|
}
|