func (this *ReceiveComponent) Unpacket(buff []byte, remoteaddr *net.UDPAddr) {
	if len(buff) != 0 {
		msgaudio := model.Request{}
		err := msgaudio.Decode(buff)
		if err != nil {
			return
		}

		switch msgaudio.Type {
		case define.SEND:
			GetSendComponent().Push(&msgaudio)
		case define.REGISTER:
			this.RegisterMsgHandle(&msgaudio, remoteaddr)
		default:
		}
	}
}
Example #2
0
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)
	}
}