func (this *DeleteComponent) MsgHandle(msg *model.Operation) { for _, v := range msg.List { err := model.GetUsers().Remove(v.Uuid, v.DeviceId) if err != nil { continue } fmt.Println("Ok - delete uuid ", v.Uuid, v.DeviceId) } }
func (this *RegisterComponent) MsgHandle(request *model.Register) { audio := request.Request Conn := &net.UDPAddr{ IP: request.IP, Port: int(request.Port), } err := model.GetUsers().Add(request.FromUuid, request.FromDeviceId, request.DestUuid, request.DestDeviceId, request.IP, request.Port, Conn) if err != nil { err = model.GetUsers().Update(request.FromUuid, request.FromDeviceId, request.DestUuid, request.DestDeviceId, request.IP, request.Port, Conn) if err != nil { audio.Type = define.REGISTER_ERR fmt.Println("Register Component MsgHandle - register ", request.FromUuid, request.FromDeviceId) } else { audio.Type = define.REGISTER_OK fmt.Println("Register Component MsgHandle Ok - register ", request.FromUuid, request.FromDeviceId) } } else { audio.Type = define.REGISTER_OK fmt.Println("Register Component MsgHandle Ok - register ", request.FromUuid, request.FromDeviceId) } if user := model.GetUsers().Get(request.DestUuid, request.DestDeviceId); user != nil && user.Conn != nil && user.BindUuid == request.FromUuid && user.BindDeviceId == request.FromDeviceId { buff, err := audio.Encode() if err != nil { err = fmt.Errorf("Register Component MsgHandle Error:%v", err) fmt.Println(err.Error()) return } for i := 0; i < this.RegisterResponseCount; i++ { GetReceiveComponent().Write(buff, request.IP, request.Port) GetReceiveComponent().Write(buff, user.IP, user.Port) } } }
func (this *SendComponent) MsgHandle(audio *model.Request) { if user := model.GetUsers().Get(audio.DestUuid, audio.DestDeviceId); user != nil && user.Conn != nil && user.BindUuid == audio.FromUuid && user.BindDeviceId == audio.FromDeviceId { audio.DestUuid, audio.FromUuid = audio.FromUuid, audio.DestUuid audio.DestDeviceId, audio.FromDeviceId = audio.FromDeviceId, audio.DestDeviceId buff, err := audio.Encode() if err == nil { n, err := GetReceiveComponent().Write(buff, user.IP, user.Port) // n, err := user.Conn.Write(buff) if n == 0 || err != nil { fmt.Println("Send Component MsgHandle Error : send", audio.DestUuid, audio.DestDeviceId, err) return } fmt.Println("Send Component MsgHandle Ok :send ", audio.DestUuid, audio.DestDeviceId) } } else { fmt.Println("Send Component MsgHandle Error :not found user", audio.DestUuid, audio.DestDeviceId) } }