Skip to content

Commit

Permalink
add some local log
Browse files Browse the repository at this point in the history
  • Loading branch information
szpnygo committed Oct 12, 2022
1 parent 1db7681 commit 0768ed7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions client/layout/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ func (lm *LayoutManager) UpdateSelectedRoom(g *gocui.Gui, room string) error {
}

func (lm *LayoutManager) UpdateMessageBar(msg string, color string) {
log.GTCLog.Warning(msg)
colorNum := 31
switch color {
case "green":
Expand Down
18 changes: 16 additions & 2 deletions client/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/metagogs/gogs/proto"
"github.com/pterm/pterm"
"github.com/szpnygo/gtc/client/layout"
"github.com/szpnygo/gtc/log"
"github.com/szpnygo/gtc/p2p"
"github.com/szpnygo/gtc/server/model"

Expand Down Expand Up @@ -79,6 +80,10 @@ func (c *ClientServer) Stop() {
func (c *ClientServer) login() {
// connect to signaling server
conn, _, err := websocket.DefaultDialer.Dial(fmt.Sprintf("%s/gtc", c.api), nil)
conn.SetCloseHandler(func(code int, text string) error {
c.layout.UpdateMessageBar(fmt.Sprintf("websocket connection closed %d %s", code, text), "red")
return nil
})
if err != nil {
pterm.Error.Println(err)
panic(err)
Expand Down Expand Up @@ -106,6 +111,7 @@ func (c *ClientServer) readSignalingMessage() {
for {
_, data, err := c.signalingConn.ReadMessage()
if err != nil {
log.GTCLog.Error(err)
break
}
c.parseSignalingMessage(data)
Expand All @@ -114,7 +120,11 @@ func (c *ClientServer) readSignalingMessage() {

func (c *ClientServer) sendSignalingMessage(in any) {
if data, err := c.codecHelper.Encode(in); err == nil {
_ = c.signalingConn.WriteMessage(websocket.BinaryMessage, data.ToData().B)
if err := c.signalingConn.WriteMessage(websocket.BinaryMessage, data.ToData().B); err != nil {
log.GTCLog.Error(err)
}
} else {
log.GTCLog.Error(err)
}
}

Expand Down Expand Up @@ -157,16 +167,19 @@ func (c *ClientServer) Candidate(in *model.Candidate) {
}

func (c *ClientServer) ListRoomResponse(in *model.ListRoomResponse) {
log.GTCLog.Info("ListRoomResponse")
c.layout.UpdateRoomList(in.Rooms)
}

func (c *ClientServer) JoinRoomSuccess(in *model.JoinRoomSuccess) {
c.layout.UpdateMessageBar("join room success", "green")
log.GTCLog.Info("JoinRoomSuccess")
c.layout.UpdateMessageBar(fmt.Sprintf("join room success %s", in.RoomId), "green")
c.layout.WriteMessage(c.layout.GetUsername(), "join room")
c.layout.UpdateUserList(in.Users)
}

func (c *ClientServer) JoinRoomNotify(in *model.JoinRoomNotify) {
log.GTCLog.Info("JoinRoomNotify")
c.layout.WriteMessage(in.Name, "join room")
c.layout.UpdateUserList(in.Users)

Expand All @@ -187,6 +200,7 @@ func (c *ClientServer) JoinRoomNotify(in *model.JoinRoomNotify) {
}

func (c *ClientServer) LeaveRoomNotify(in *model.LeaveRoomNotify) {
log.GTCLog.Info("LeaveRoomNotify")
c.layout.WriteMessage(in.Name, "leave room")
c.layout.UpdateUserList(in.Users)

Expand Down
4 changes: 3 additions & 1 deletion p2p/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,7 @@ func (p *P2PClient) OnICECandidate(candidate []byte) error {
}

func (p *P2PClient) SendMessage(msg []byte) {
_ = p.dataChannel.Send(msg)
if err := p.dataChannel.Send(msg); err != nil {
log.GTCLog.Error(err)
}
}

0 comments on commit 0768ed7

Please sign in to comment.