|
|
|
|
@ -3,6 +3,8 @@ package room
|
|
|
|
|
import (
|
|
|
|
|
"io"
|
|
|
|
|
|
|
|
|
|
json "github.com/json-iterator/go"
|
|
|
|
|
|
|
|
|
|
"github.com/gorilla/websocket"
|
|
|
|
|
pb "github.com/synctv-org/synctv/proto"
|
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
|
|
|
@ -11,7 +13,23 @@ import (
|
|
|
|
|
type Message interface {
|
|
|
|
|
MessageType() int
|
|
|
|
|
String() string
|
|
|
|
|
Encode(wc io.Writer) error
|
|
|
|
|
Encode(w io.Writer) error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ElementJsonMessage struct {
|
|
|
|
|
*pb.ElementMessage
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (em *ElementJsonMessage) MessageType() int {
|
|
|
|
|
return websocket.TextMessage
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (em *ElementJsonMessage) String() string {
|
|
|
|
|
return em.ElementMessage.String()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (em *ElementJsonMessage) Encode(w io.Writer) error {
|
|
|
|
|
return json.NewEncoder(w).Encode(em)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type ElementMessage struct {
|
|
|
|
|
@ -23,44 +41,15 @@ func (em *ElementMessage) MessageType() int {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (em *ElementMessage) String() string {
|
|
|
|
|
// out, _ := yaml.Marshal(em)
|
|
|
|
|
// switch em.Type {
|
|
|
|
|
// case Error:
|
|
|
|
|
// return fmt.Sprintf("Element Error: %s", out)
|
|
|
|
|
// case ChatMessage:
|
|
|
|
|
// return fmt.Sprintf("Element ChatMessage: %s", out)
|
|
|
|
|
// case Play:
|
|
|
|
|
// return fmt.Sprintf("Element Play: %s", out)
|
|
|
|
|
// case Pause:
|
|
|
|
|
// return fmt.Sprintf("Element Pause: %s", out)
|
|
|
|
|
// case CheckSeek:
|
|
|
|
|
// return fmt.Sprintf("Element CheckSeek: %s", out)
|
|
|
|
|
// case TooFast:
|
|
|
|
|
// return fmt.Sprintf("Element TooFast: %s", out)
|
|
|
|
|
// case TooSlow:
|
|
|
|
|
// return fmt.Sprintf("Element TooSlow: %s", out)
|
|
|
|
|
// case ChangeRate:
|
|
|
|
|
// return fmt.Sprintf("Element ChangeRate: %s", out)
|
|
|
|
|
// case ChangeSeek:
|
|
|
|
|
// return fmt.Sprintf("Element ChangeSeek: %s", out)
|
|
|
|
|
// case ChangeCurrent:
|
|
|
|
|
// return fmt.Sprintf("Element ChangeCurrent: %s", out)
|
|
|
|
|
// case ChangeMovies:
|
|
|
|
|
// return fmt.Sprintf("Element ChangeMovieList: %s", out)
|
|
|
|
|
// case ChangePeople:
|
|
|
|
|
// return fmt.Sprintf("Element ChangePeopleNum: %s", out)
|
|
|
|
|
// default:
|
|
|
|
|
// return fmt.Sprintf("Element Unknown: %s", out)
|
|
|
|
|
// }
|
|
|
|
|
return ""
|
|
|
|
|
return em.ElementMessage.String()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (em *ElementMessage) Encode(wc io.Writer) error {
|
|
|
|
|
func (em *ElementMessage) Encode(w io.Writer) error {
|
|
|
|
|
b, err := proto.Marshal(em)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
_, err = wc.Write(b)
|
|
|
|
|
_, err = w.Write(b)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -74,6 +63,6 @@ func (pm *PingMessage) String() string {
|
|
|
|
|
return "Ping"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (pm *PingMessage) Encode(wc io.Writer) error {
|
|
|
|
|
func (pm *PingMessage) Encode(w io.Writer) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|