mic_change.go 3.07 KB
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3
package event_s

import (
hujiebin's avatar
hujiebin committed
4
	"encoding/json"
hujiebin's avatar
hujiebin committed
5
	"git.hilo.cn/hilo-common/domain"
hujiebin's avatar
hujiebin committed
6
	"git.hilo.cn/hilo-common/protocol/userProxy"
hujiebin's avatar
hujiebin committed
7
	"git.hilo.cn/hilo-common/rpc"
8
	uuid "github.com/satori/go.uuid"
hujiebin's avatar
hujiebin committed
9
	"hilo-group/domain/event/group_ev"
hujiebin's avatar
hujiebin committed
10
	"hilo-group/domain/model/group_m"
hujiebin's avatar
hujiebin committed
11 12 13 14 15 16 17 18 19 20
	"hilo-group/myerr/bizerr"
)

// 用户进房后推送mic信息
func GroupInMicChangeEvent() {
	group_ev.AddTxGroupInEventAsync(func(model *domain.Model, event interface{}) error {
		e, ok := event.(*group_ev.TxGroupInEvent)
		if !ok {
			return bizerr.InvalidParameter
		}
hujiebin's avatar
hujiebin committed
21
		return MicAllRPush(model, e.GroupId, e.UserId, e.ExternalId)
hujiebin's avatar
hujiebin committed
22 23
	})
}
hujiebin's avatar
hujiebin committed
24

hujiebin's avatar
hujiebin committed
25 26
func MicAllRPush(model *domain.Model, imGroupId string, userId uint64, externalId string) error {
	model.Log.Infof("MicChangeRPush MicAllRPush begin groupUuid:%v, externalId:%v", imGroupId, externalId)
hujiebin's avatar
hujiebin committed
27

hujiebin's avatar
hujiebin committed
28
	txGroupId, err := group_m.ToTxGroupId(model, imGroupId)
hujiebin's avatar
hujiebin committed
29 30 31 32 33 34 35
	if err != nil {
		model.Log.Errorf("ToImGroupId fail:%v", err)
		return err
	}
	//
	micContents, err := group_m.GetMicAllContent(model, imGroupId)
	if err != nil {
hujiebin's avatar
hujiebin committed
36
		model.Log.Errorf("MicChangeRPush MicAllRPush getMicAllContent  err:%+v, micContents:%v groupUuid:%v, externalId:%v", err, micContents, txGroupId, externalId)
hujiebin's avatar
hujiebin committed
37 38 39 40 41
		return err
	}
	for _, micContent := range micContents {
		//麦上是默认值,就不用推
		if micContent.Forbid == false && micContent.User == nil && micContent.AgoraId == 0 && micContent.Lock == false && micContent.ExternalId == "" && micContent.MicForbid == false {
hujiebin's avatar
hujiebin committed
42
			model.Log.Infof("MicChangeRPush MicAllRPush default micContent:%v, groupUuid:%v, externalId:%v, micContent:%+v", micContent, txGroupId, externalId, micContent)
hujiebin's avatar
hujiebin committed
43 44 45 46 47 48
			continue
		}
		micContentStr, err := json.Marshal(micContent)
		if err != nil {
			continue
		}
hujiebin's avatar
hujiebin committed
49 50 51 52
		tmpMicUser := new(group_m.MicUserData)
		if micContent.User != nil {
			tmpMicUser = micContent.User
		}
53
		seqId := uuid.NewV4().String()
hujiebin's avatar
hujiebin committed
54 55 56 57 58 59 60 61 62 63 64
		svip := &userProxy.Svip{
			SvipLevel: uint64(tmpMicUser.SvipLevel),
		}
		for _, v := range tmpMicUser.Svip.Privileges {
			svip.Privileges = append(svip.Privileges, &userProxy.SvipPrivilege{
				Type:        int32(v.Type),
				CanSwitch:   v.CanSwitch,
				UserSwitch:  v.UserSwitch,
				MysteryCode: v.MysteryCode,
			})
		}
hujiebin's avatar
hujiebin committed
65
		if err := rpc.SendSocketMicChange(seqId, userId, externalId, txGroupId, uint32(micContent.I), micContent.Lock, micContent.Forbid, micContent.MicForbid, micContent.AgoraId,
hujiebin's avatar
hujiebin committed
66
			tmpMicUser.Id, tmpMicUser.ExternalId, tmpMicUser.Avatar, tmpMicUser.Nick, uint32(tmpMicUser.Sex), tmpMicUser.Code, tmpMicUser.IsVip, uint32(tmpMicUser.NobleLeave),
hujiebin's avatar
hujiebin committed
67
			tmpMicUser.HeadwearPicUrl, tmpMicUser.HeadwearEffectUrl, tmpMicUser.HeadwearReverseEffectUrl, uint32(tmpMicUser.SvipLevel), tmpMicUser.MicEffect, tmpMicUser.HeadwearIcon, svip); err != nil {
hujiebin's avatar
hujiebin committed
68
			model.Log.Errorf("MicAllRPush err:%+v, groupUuid:%v, externalId:%v, micContent:%+v", err, txGroupId, externalId, string(micContentStr))
hujiebin's avatar
hujiebin committed
69
		} else {
hujiebin's avatar
hujiebin committed
70
			model.Log.Infof("MicChangeRPush MicAllRPush Marshal micContent, groupUuid:%v, externalId:%v, micContent:%+v", txGroupId, externalId, string(micContentStr))
hujiebin's avatar
hujiebin committed
71 72
		}
	}
hujiebin's avatar
hujiebin committed
73
	model.Log.Infof("MicAllRPush end groupUuid:%v, externalId:%v", txGroupId, externalId)
hujiebin's avatar
hujiebin committed
74 75
	return nil
}