fix leave

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Vasiliy Tolstov 2023-01-25 01:57:16 +03:00
parent d9e6c4edbc
commit b17b989e28

View file

@ -24,7 +24,7 @@ func main() {
c, err := ably.NewRealtime( c, err := ably.NewRealtime(
ably.WithAutoConnect(true), ably.WithAutoConnect(true),
ably.WithToken(authToken), ably.WithToken(authToken),
// ably.WithLogLevel(ably.LogDebug), ably.WithLogLevel(ably.LogDebug),
ably.WithAuthMethod(http.MethodGet), ably.WithAuthMethod(http.MethodGet),
ably.WithUseTokenAuth(true), ably.WithUseTokenAuth(true),
ably.WithRealtimeHost("realtime.pa.highwebmedia.com"), ably.WithRealtimeHost("realtime.pa.highwebmedia.com"),
@ -42,7 +42,9 @@ func main() {
type leaveMsg struct { type leaveMsg struct {
Action string `json:"action"` Action string `json:"action"`
User struct {
IsBroadcaster bool `json:"is_broadcaster"` IsBroadcaster bool `json:"is_broadcaster"`
} `json:"user"`
} }
tipChannel := "room:tip_alert:" + room_uid tipChannel := "room:tip_alert:" + room_uid
@ -57,7 +59,10 @@ func main() {
cancel() cancel()
return return
} }
if leave.Action == "leave" && leave.IsBroadcaster { /*
*/
if leave.Action == "leave" && leave.User.IsBroadcaster {
fmt.Println("user finished and exit") fmt.Println("user finished and exit")
cancel() cancel()
return return