1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package webssh
import (
"io"
"github.com/gliderlabs/ssh"
socketio "github.com/googollee/go-socket.io"
"cocogo/pkg/model"
)
type Client struct {
Uuid string
Cid string
user *model.User
addr string
WinChan chan ssh.Window
UserRead io.Reader
UserWrite io.WriteCloser
Conn socketio.Conn
Closed bool
}
func (c *Client) Protocol() string {
return "ws"
}
func (c *Client) WinCh() <-chan ssh.Window {
return c.WinChan
}
func (c *Client) User() string {
return c.user.Username
}
func (c *Client) LoginFrom() string {
return "WT"
}
func (c *Client) RemoteAddr() string {
return c.addr
}
func (c *Client) Read(p []byte) (n int, err error) {
return c.UserRead.Read(p)
}
func (c *Client) Write(p []byte) (n int, err error) {
data := DataMsg{Data: string(p), Room: c.Uuid}
n = len(p)
c.Conn.Emit("data", data)
return
}
func (c *Client) Close() (err error) {
if c.Closed {
return
}
return c.UserWrite.Close()
}