-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathhandle.go
664 lines (647 loc) · 20.6 KB
/
handle.go
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
package acfundanmu
import (
"bytes"
"compress/gzip"
"context"
"encoding/base64"
"fmt"
"io"
"log"
"sort"
"github.com/orzogc/acfundanmu/acproto"
"google.golang.org/protobuf/proto"
)
// 处理接受到的数据里的命令
func (ac *AcFunLive) handleCommand(ctx context.Context, stream *acproto.DownstreamPayload, event bool) (e error) {
defer func() {
if err := recover(); err != nil {
e = fmt.Errorf("handleCommand() error: %v", err)
}
}()
if stream == nil {
panic(fmt.Errorf("stream 为 nil"))
}
switch stream.Command {
case "Global.ZtLiveInteractive.CsCmd":
cmd := &acproto.ZtLiveCsCmdAck{}
err := proto.Unmarshal(stream.PayloadData, cmd)
checkErr(err)
switch cmd.CmdAckType {
case "ZtLiveCsEnterRoomAck":
enterRoom := &acproto.ZtLiveCsEnterRoomAck{}
err = proto.Unmarshal(cmd.Payload, enterRoom)
checkErr(err)
if enterRoom.HeartbeatIntervalMs > 0 {
go ac.clientHeartbeat(ctx, enterRoom.HeartbeatIntervalMs)
} else {
go ac.clientHeartbeat(ctx, 10000)
}
case "ZtLiveCsHeartbeatAck":
//heartbeat := &acproto.ZtLiveCsHeartbeatAck{}
//err = proto.Unmarshal(cmd.Payload, heartbeat)
//checkErr(err)
case "ZtLiveCsUserExitAck":
//userExit := &acproto.ZtLiveCsUserExitAck{}
//err = proto.Unmarshal(cmd.Payload, userExit)
//checkErr(err)
default:
log.Printf("未知的cmd.CmdAckType:%s\npayload string:\n%s\npayload base64:\n%s\n",
cmd.CmdAckType,
string(cmd.Payload),
base64.StdEncoding.EncodeToString(cmd.Payload))
}
case "Basic.Handshake":
handshake := &acproto.HansshakeResponse{}
err := proto.Unmarshal(stream.PayloadData, handshake)
checkErr(err)
_, err = ac.danmuClient.Write(ac.t.register())
checkErr(err)
case "Basic.Register":
register := &acproto.RegisterResponse{}
err := proto.Unmarshal(stream.PayloadData, register)
checkErr(err)
ac.t.instanceID = register.InstanceId
ac.t.sessionKey = register.SessKey
_, err = ac.danmuClient.Write(ac.t.keepAlive())
checkErr(err)
_, err = ac.danmuClient.Write(ac.t.enterRoom())
checkErr(err)
case "Basic.KeepAlive":
//keepalive := &acproto.KeepAliveResponse{}
//err := proto.Unmarshal(stream.PayloadData, keepalive)
//checkErr(err)
case "Basic.Ping":
//ping := &acproto.PingResponse{}
//err := proto.Unmarshal(stream.PayloadData, ping)
//checkErr(err)
case "Basic.Unregister":
unregister := &acproto.UnregisterResponse{}
err := proto.Unmarshal(stream.PayloadData, unregister)
checkErr(err)
ac.t.err.Store(fmt.Errorf("接收到 Unregister 信号"))
_ = ac.danmuClient.Close("Unregister")
case "Push.ZtLiveInteractive.Message":
_, err := ac.danmuClient.Write(ac.t.pushMessage())
checkErr(err)
message := &acproto.ZtLiveScMessage{}
err = proto.Unmarshal(stream.PayloadData, message)
checkErr(err)
payload := message.Payload
if message.CompressionType == acproto.ZtLiveScMessage_GZIP {
r, err := gzip.NewReader(bytes.NewReader(message.Payload))
checkErr(err)
defer r.Close()
payload, err = io.ReadAll(r)
checkErr(err)
}
switch message.MessageType {
case "ZtLiveScActionSignal":
ac.handleActionSignal(&payload, event)
case "ZtLiveScStateSignal":
ac.handleStateSignal(&payload, event)
case "ZtLiveScNotifySignal":
ac.handleNotifySignal(&payload, event)
case "ZtLiveScStatusChanged":
statusChanged := &acproto.ZtLiveScStatusChanged{}
err = proto.Unmarshal(payload, statusChanged)
checkErr(err)
if statusChanged.Type == acproto.ZtLiveScStatusChanged_LIVE_CLOSED || statusChanged.Type == acproto.ZtLiveScStatusChanged_LIVE_BANNED {
ac.clientStop("Live closed")
}
case "ZtLiveScTicketInvalid":
ticketInvalid := &acproto.ZtLiveScTicketInvalid{}
err = proto.Unmarshal(payload, ticketInvalid)
checkErr(err)
index := ac.t.ticketIndex.Load()
_ = ac.t.ticketIndex.CompareAndSwap(index, (index+1)%uint32(len(ac.t.tickets)))
_, err = ac.danmuClient.Write(ac.t.enterRoom())
checkErr(err)
default:
log.Printf("未知的message.MessageType:%s\npayload string:\n%s\npayload base64:\n%s\n",
message.MessageType,
string(payload),
base64.StdEncoding.EncodeToString(payload))
}
// AcFun 帐号收到的私信信息
case "Push.Message":
case "Push.DataUpdate":
case "Push.SyncSession":
case "Push.acfun":
default:
if stream.ErrorCode > 0 {
log.Println("DownstreamPayload error:", stream.ErrorCode, stream.ErrorMsg)
if stream.ErrorCode == 10018 {
ac.t.err.Store(fmt.Errorf(string(stream.ErrorData)))
ac.clientStop("Log out")
} else {
log.Printf("接收弹幕出现错误:%s", string(stream.ErrorData))
}
} else {
log.Printf("未知的stream.Command:%s\npayload string:\n%s\npayload base64:\n%s\n",
stream.Command,
string(stream.PayloadData),
base64.StdEncoding.EncodeToString(stream.PayloadData))
}
}
return nil
}
// 处理 action signal 数据
func (ac *AcFunLive) handleActionSignal(payload *[]byte, event bool) {
actionSignal := &acproto.ZtLiveScActionSignal{}
err := proto.Unmarshal(*payload, actionSignal)
checkErr(err)
var danmu []DanmuMessage
for _, item := range actionSignal.Item {
for _, pl := range item.Payload {
switch item.SignalType {
case "CommonActionSignalComment":
comment := &acproto.CommonActionSignalComment{}
err = proto.Unmarshal(pl, comment)
checkErr(err)
d := &Comment{
DanmuCommon: DanmuCommon{
SendTime: comment.SendTimeMs,
UserInfo: *NewUserInfo(comment.UserInfo),
},
Content: comment.Content,
}
danmu = append(danmu, d)
case "CommonActionSignalLike":
like := &acproto.CommonActionSignalLike{}
err = proto.Unmarshal(pl, like)
checkErr(err)
d := &Like{
SendTime: like.SendTimeMs,
UserInfo: *NewUserInfo(like.UserInfo),
}
danmu = append(danmu, d)
case "CommonActionSignalUserEnterRoom":
enter := &acproto.CommonActionSignalUserEnterRoom{}
err = proto.Unmarshal(pl, enter)
checkErr(err)
d := &EnterRoom{
SendTime: enter.SendTimeMs,
UserInfo: *NewUserInfo(enter.UserInfo),
}
danmu = append(danmu, d)
case "CommonActionSignalUserFollowAuthor":
follow := &acproto.CommonActionSignalUserFollowAuthor{}
err = proto.Unmarshal(pl, follow)
checkErr(err)
d := &FollowAuthor{
SendTime: follow.SendTimeMs,
UserInfo: *NewUserInfo(follow.UserInfo),
}
danmu = append(danmu, d)
case "AcfunActionSignalThrowBanana":
banana := &acproto.AcfunActionSignalThrowBanana{}
err = proto.Unmarshal(pl, banana)
checkErr(err)
d := &ThrowBanana{
DanmuCommon: DanmuCommon{
SendTime: banana.SendTimeMs,
UserInfo: UserInfo{
UserID: banana.Visitor.UserId,
Nickname: banana.Visitor.Name,
},
},
BananaCount: int(banana.Count),
}
danmu = append(danmu, d)
case "CommonActionSignalGift":
gift := &acproto.CommonActionSignalGift{}
err = proto.Unmarshal(pl, gift)
checkErr(err)
ac.t.giftsMutex.RLock()
g, ok := ac.t.gifts[gift.GiftId]
ac.t.giftsMutex.RUnlock()
// 存在未知礼物时
if !ok {
list, err := ac.t.getGiftList(ac.t.liveID)
if err != nil {
log.Printf("获取礼物列表出现错误:%v", err)
g = GiftDetail{
GiftID: gift.GiftId,
GiftName: "未知礼物",
}
} else {
ac.t.giftsMutex.Lock()
ac.t.gifts = list
g, ok = ac.t.gifts[gift.GiftId]
if !ok {
g = GiftDetail{
GiftID: gift.GiftId,
GiftName: "未知礼物",
}
}
ac.t.giftsMutex.Unlock()
}
}
d := &Gift{
DanmuCommon: DanmuCommon{
SendTime: gift.SendTimeMs,
UserInfo: *NewUserInfo(gift.UserInfo),
},
GiftDetail: g,
Count: gift.BatchSize,
Combo: gift.ComboCount,
Value: gift.Rank,
ComboID: gift.ComboKey,
SlotDisplayDuration: gift.SlotDisplayDurationMs,
ExpireDuration: gift.ExpireDurationMs,
}
if gift.DrawGiftInfo != nil {
d.DrawGiftInfo = DrawGiftInfo{
ScreenWidth: gift.DrawGiftInfo.ScreenWidth,
ScreenHeight: gift.DrawGiftInfo.ScreenHeight,
}
d.DrawGiftInfo.DrawPoint = make([]DrawPoint, len(gift.DrawGiftInfo.DrawPoint))
for i, drawPoint := range gift.DrawGiftInfo.DrawPoint {
d.DrawGiftInfo.DrawPoint[i] = DrawPoint{
MarginLeft: drawPoint.MarginLeft,
MarginTop: drawPoint.MarginTop,
ScaleRatio: drawPoint.ScaleRatio,
Handup: drawPoint.Handup,
PointWidth: drawPoint.PointWidth,
PointHeight: drawPoint.PointHeight,
}
}
}
danmu = append(danmu, d)
case "CommonActionSignalRichText":
richText := &acproto.CommonActionSignalRichText{}
err = proto.Unmarshal(pl, richText)
checkErr(err)
d := &RichText{
SendTime: richText.SendTimeMs,
}
d.Segments = make([]RichTextSegment, len(richText.Segments))
for i, segment := range richText.Segments {
switch segment := segment.Segment.(type) {
case *acproto.CommonActionSignalRichText_RichTextSegment_UserInfo:
userInfo := &RichTextUserInfo{
UserInfo: *NewUserInfo(segment.UserInfo.User),
Color: segment.UserInfo.Color,
}
d.Segments[i] = userInfo
case *acproto.CommonActionSignalRichText_RichTextSegment_Plain:
plain := &RichTextPlain{
Text: segment.Plain.Text,
Color: segment.Plain.Color,
}
d.Segments[i] = plain
case *acproto.CommonActionSignalRichText_RichTextSegment_Image:
image := &RichTextImage{
AlternativeText: segment.Image.AlternativeText,
AlternativeColor: segment.Image.AlternativeColor,
}
image.Pictures = make([]string, len(segment.Image.Pictures))
for j, picture := range segment.Image.Pictures {
image.Pictures[j] = picture.Url
}
d.Segments[i] = image
default:
log.Println("出现未处理的 RichText Segment")
}
}
danmu = append(danmu, d)
case "AcfunActionSignalJoinClub":
join := &acproto.AcfunActionSignalJoinClub{}
err = proto.Unmarshal(pl, join)
checkErr(err)
d := &JoinClub{
JoinTime: join.JoinTimeMs,
FansInfo: UserInfo{
UserID: join.FansInfo.UserId,
Nickname: join.FansInfo.Name,
},
UperInfo: UserInfo{
UserID: join.UperInfo.UserId,
Nickname: join.UperInfo.Name,
},
}
danmu = append(danmu, d)
case "CommonActionSignalUserShareLive":
share := &acproto.CommonActionSignalUserShareLive{}
err = proto.Unmarshal(pl, share)
checkErr(err)
d := &ShareLive{
DanmuCommon: DanmuCommon{
SendTime: share.SendTimeMs,
UserInfo: *NewUserInfo(share.UserInfo),
},
SharePlatform: SharePlatformType(share.SharePlatformId),
SharePlatformIcon: share.SharePlatformIcon,
}
danmu = append(danmu, d)
default:
log.Printf("未知的Action Signal item.SignalType:%s\npayload string:\n%s\npayload base64:\n%s\n",
item.SignalType,
string(pl),
base64.StdEncoding.EncodeToString(pl))
}
}
}
// 按 SendTime 大小排序
sort.Slice(danmu, func(i, j int) bool {
return danmu[i].GetSendTime() < danmu[j].GetSendTime()
})
for _, d := range danmu {
if event {
switch d := d.(type) {
case *Comment:
ac.callEvent(commentDanmu, d)
case *Like:
ac.callEvent(likeDanmu, d)
case *EnterRoom:
ac.callEvent(enterRoomDanmu, d)
case *FollowAuthor:
ac.callEvent(followAuthorDanmu, d)
case *ThrowBanana:
ac.callEvent(throwBananaDanmu, d)
case *Gift:
ac.callEvent(giftDanmu, d)
case *RichText:
ac.callEvent(richTextDanmu, d)
case *JoinClub:
ac.callEvent(joinClubDanmu, d)
case *ShareLive:
ac.callEvent(shareLiveDanmu, d)
default:
log.Println("出现未处理的 DanmuMessage")
}
} else {
err = ac.q.Put(d)
checkErr(err)
}
}
}
// 处理 state signal 数据
func (ac *AcFunLive) handleStateSignal(payload *[]byte, event bool) {
stateSignal := &acproto.ZtLiveScStateSignal{}
err := proto.Unmarshal(*payload, stateSignal)
checkErr(err)
for _, item := range stateSignal.Item {
switch item.SignalType {
case "AcfunStateSignalDisplayInfo":
bananaInfo := &acproto.AcfunStateSignalDisplayInfo{}
err = proto.Unmarshal(item.Payload, bananaInfo)
checkErr(err)
if event {
ac.callEvent(bananaCountEvent, bananaInfo.BananaCount)
} else {
ac.info.Lock()
ac.info.AllBananaCount = bananaInfo.BananaCount
ac.info.Unlock()
}
case "CommonStateSignalDisplayInfo":
stateInfo := &acproto.CommonStateSignalDisplayInfo{}
err = proto.Unmarshal(item.Payload, stateInfo)
checkErr(err)
info := DisplayInfo{
WatchingCount: stateInfo.WatchingCount,
LikeCount: stateInfo.LikeCount,
LikeDelta: int(stateInfo.LikeDelta),
}
if event {
ac.callEvent(displayEvent, &info)
} else {
ac.info.Lock()
ac.info.DisplayInfo = info
ac.info.Unlock()
}
case "CommonStateSignalTopUsers":
topUsers := &acproto.CommonStateSignalTopUsers{}
err = proto.Unmarshal(item.Payload, topUsers)
checkErr(err)
users := make([]TopUser, len(topUsers.User))
for i, user := range topUsers.User {
u := TopUser{
UserInfo: *NewUserInfo(user.UserInfo),
AnonymousUser: user.AnonymousUser,
DisplaySendAmount: user.DisplaySendAmount,
CustomData: user.CustomWatchingListData,
}
users[i] = u
}
if event {
ac.callEvent(topUsersEvent, users)
} else {
ac.info.Lock()
ac.info.TopUsers = users
ac.info.Unlock()
}
case "CommonStateSignalRecentComment":
comments := &acproto.CommonStateSignalRecentComment{}
err = proto.Unmarshal(item.Payload, comments)
checkErr(err)
danmu := make([]Comment, len(comments.Comment))
for i, comment := range comments.Comment {
d := Comment{
DanmuCommon: DanmuCommon{
SendTime: comment.SendTimeMs,
UserInfo: *NewUserInfo(comment.UserInfo),
},
Content: comment.Content,
}
danmu[i] = d
}
if event {
ac.callEvent(recentCommentEvent, danmu)
} else {
ac.info.Lock()
ac.info.RecentComment = danmu
ac.info.Unlock()
}
case "CommonStateSignalCurrentRedpackList":
redpackList := &acproto.CommonStateSignalCurrentRedpackList{}
err = proto.Unmarshal(item.Payload, redpackList)
checkErr(err)
redpacks := make([]Redpack, len(redpackList.Redpacks))
for i, redpack := range redpackList.Redpacks {
r := Redpack{
UserInfo: *NewUserInfo(redpack.Sender),
DisplayStatus: RedpackDisplayStatus(redpack.DisplayStatus),
GrabBeginTime: redpack.GrabBeginTimeMs,
GetTokenLatestTime: redpack.GetTokenLatestTimeMs,
RedpackID: redpack.RedPackId,
RedpackBizUnit: redpack.RedpackBizUnit,
RedpackAmount: redpack.RedpackAmount,
SettleBeginTime: redpack.SettleBeginTime,
}
redpacks[i] = r
}
if event {
ac.callEvent(redpackListEvent, redpacks)
} else {
ac.info.Lock()
ac.info.RedpackList = redpacks
ac.info.Unlock()
}
case "CommonStateSignalChatCall":
chatCall := &acproto.CommonStateSignalChatCall{}
err = proto.Unmarshal(item.Payload, chatCall)
checkErr(err)
if event {
ac.callEvent(chatCallEvent, &ChatCall{
ChatID: chatCall.ChatId,
LiveID: chatCall.LiveId,
CallTime: chatCall.CallTimestampMs,
})
}
case "CommonStateSignalChatAccept":
chatAccept := &acproto.CommonStateSignalChatAccept{}
err = proto.Unmarshal(item.Payload, chatAccept)
checkErr(err)
if event {
ac.callEvent(chatAcceptEvent, &ChatAccept{
ChatID: chatAccept.ChatId,
MediaType: ChatMediaType(chatAccept.MediaType),
SignalInfo: chatAccept.AryaSignalInfo,
})
}
case "CommonStateSignalChatReady":
chatReady := &acproto.CommonStateSignalChatReady{}
err = proto.Unmarshal(item.Payload, chatReady)
checkErr(err)
if event {
ac.callEvent(chatReadyEvent, &ChatReady{
ChatID: chatReady.ChatId,
Guest: *NewUserInfo(chatReady.GuestUserInfo),
MediaType: ChatMediaType(chatReady.MediaType),
})
}
case "CommonStateSignalChatEnd":
chatEnd := &acproto.CommonStateSignalChatEnd{}
err = proto.Unmarshal(item.Payload, chatEnd)
checkErr(err)
if event {
ac.callEvent(chatEndEvent, &ChatEnd{
ChatID: chatEnd.ChatId,
EndType: ChatEndType(chatEnd.EndType),
})
}
//case "AuthorChatPlayerInfo":
case "CommonStateSignalAuthorChatCall":
chatCall := &acproto.CommonStateSignalAuthorChatCall{}
err = proto.Unmarshal(item.Payload, chatCall)
checkErr(err)
if event {
ac.callEvent(authorChatCallEvent, &AuthorChatCall{
Inviter: AuthorChatPlayerInfo{
UserInfo: *NewUserInfo(chatCall.InviterUserInfo.Player),
LiveID: chatCall.InviterUserInfo.LiveId,
EnableJumpPeerLiveRoom: chatCall.InviterUserInfo.EnableJumpPeerLiveRoom,
},
ChatID: chatCall.AuthorChatId,
CallTime: chatCall.CallTimestampMs,
})
}
case "CommonStateSignalAuthorChatAccept":
chatAccept := &acproto.CommonStateSignalAuthorChatAccept{}
err = proto.Unmarshal(item.Payload, chatAccept)
checkErr(err)
if event {
ac.callEvent(authorChatAcceptEvent, &AuthorChatAccept{
ChatID: chatAccept.AuthorChatId,
SignalInfo: chatAccept.AryaSignalInfo,
})
}
case "CommonStateSignalAuthorChatReady":
chatReady := &acproto.CommonStateSignalAuthorChatReady{}
err = proto.Unmarshal(item.Payload, chatReady)
checkErr(err)
if event {
ac.callEvent(authorChatReadyEvent, &AuthorChatReady{
Inviter: AuthorChatPlayerInfo{
UserInfo: *NewUserInfo(chatReady.InviterUserInfo.Player),
LiveID: chatReady.InviterUserInfo.LiveId,
EnableJumpPeerLiveRoom: chatReady.InviterUserInfo.EnableJumpPeerLiveRoom,
},
Invitee: AuthorChatPlayerInfo{
UserInfo: *NewUserInfo(chatReady.InviteeUserInfo.Player),
LiveID: chatReady.InviteeUserInfo.LiveId,
EnableJumpPeerLiveRoom: chatReady.InviteeUserInfo.EnableJumpPeerLiveRoom,
},
ChatID: chatReady.AuthorChatId,
})
}
case "CommonStateSignalAuthorChatEnd":
chatEnd := &acproto.CommonStateSignalAuthorChatEnd{}
err = proto.Unmarshal(item.Payload, chatEnd)
checkErr(err)
if event {
ac.callEvent(authorChatEndEvent, &AuthorChatEnd{
ChatID: chatEnd.AuthorChatId,
EndType: ChatEndType(chatEnd.EndType),
EndLiveID: chatEnd.EndLiveId,
})
}
case "CommonStateSignalAuthorChatChangeSoundConfig":
soundConfig := &acproto.CommonStateSignalAuthorChatChangeSoundConfig{}
err = proto.Unmarshal(item.Payload, soundConfig)
checkErr(err)
if event {
ac.callEvent(authorChatChangeSoundConfigEvent, &AuthorChatChangeSoundConfig{
ChatID: soundConfig.AuthorChatId,
SoundConfigChangeType: SoundConfigChangeType(soundConfig.SoundConfigChangeType),
})
}
case "CommonStateSignalLiveState":
case "CommonStateSignalArLiveTreasureBoxState":
default:
log.Printf("未知的State Signal item.SignalType:%s\npayload string:\n%s\npayload base64:\n%s\n",
item.SignalType,
string(item.Payload),
base64.StdEncoding.EncodeToString(item.Payload))
}
}
}
// 处理 notify signal 数据
func (ac *AcFunLive) handleNotifySignal(payload *[]byte, event bool) {
notifySignal := &acproto.ZtLiveScNotifySignal{}
err := proto.Unmarshal(*payload, notifySignal)
checkErr(err)
for _, item := range notifySignal.Item {
switch item.SignalType {
case "CommonNotifySignalKickedOut":
kickedOut := &acproto.CommonNotifySignalKickedOut{}
err = proto.Unmarshal(item.Payload, kickedOut)
checkErr(err)
if event {
ac.callEvent(kickedOutEvent, kickedOut.Reason)
} else {
ac.info.Lock()
ac.info.KickedOut = kickedOut.Reason
ac.info.Unlock()
}
case "CommonNotifySignalViolationAlert":
violationAlert := &acproto.CommonNotifySignalViolationAlert{}
err = proto.Unmarshal(item.Payload, violationAlert)
checkErr(err)
if event {
ac.callEvent(violationAlertEvent, violationAlert.ViolationContent)
} else {
ac.info.Lock()
ac.info.ViolationAlert = violationAlert.ViolationContent
ac.info.Unlock()
}
case "CommonNotifySignalLiveManagerState":
liveManagerState := &acproto.CommonNotifySignalLiveManagerState{}
err = proto.Unmarshal(item.Payload, liveManagerState)
checkErr(err)
if event {
ac.callEvent(managerStateEvent, ManagerState(liveManagerState.State))
} else {
ac.info.Lock()
ac.info.LiveManagerState = ManagerState(liveManagerState.State)
ac.info.Unlock()
}
default:
log.Printf("未知的Notify Signal signalType:%s\npayload string:\n%s\npayload base64:\n%s\n",
item.SignalType,
string(item.Payload),
base64.StdEncoding.EncodeToString(item.Payload))
}
}
}