forked from External/ergo
WebSocket layer to be able to connect "web" client
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.
This commit is contained in:
parent
89bdb8a321
commit
6a69a65860
4 changed files with 95 additions and 1 deletions
56
irc/websocket.go
Normal file
56
irc/websocket.go
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
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)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue