Skip to content

Commit

Permalink
Merge pull request #9 from mikuta0407/fix/streaming
Browse files Browse the repository at this point in the history
自動再接続、PINGへの対応
  • Loading branch information
mikuta0407 authored Nov 26, 2024
2 parents ab80e8e + 9a17498 commit c941f08
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions misskey/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/buger/jsonparser"
"github.com/google/uuid"
"github.com/gorilla/websocket"
"github.com/sacOO7/gowebsocket"
)

Expand Down Expand Up @@ -45,12 +46,31 @@ func (c *Client) GetStream(mode string) error {
}

socket.OnDisconnected = func(err error, socket gowebsocket.Socket) {
log.Println("Disconnected from server ")
return
log.Println("Disconnected from server.")
socket.Connect()
initialConnect(socket, mode)
}

socket.OnPingReceived = func(data string, socket gowebsocket.Socket) {
socket.SendBinary([]byte{websocket.PongMessage})
}

socket.Connect()
initialConnect(socket, mode)

for {
select {
case <-interrupt:
log.Println("interrupt")
socket.Close()
return nil
}

}

}

func initialConnect(socket gowebsocket.Socket, mode string) error {
uu, err := uuid.NewRandom()
if err != nil {
return err
Expand All @@ -73,16 +93,7 @@ func (c *Client) GetStream(mode string) error {
return errors.New("Please select mode in local/home/global")
}
socket.SendText(channelText)

for {
select {
case <-interrupt:
log.Println("interrupt")
socket.Close()
return nil
}
}

return nil
}

func printNote(message string) {
Expand Down

0 comments on commit c941f08

Please sign in to comment.