Esempio n. 1
0
func (p *Mpris) SendRequest(device *network.Device, playerList bool, volume bool, nowPlaying bool) error {
	return device.Send(MprisType, &MprisBody{
		RequestPlayerList: playerList,
		RequestVolume:     volume,
		RequestNowPlaying: nowPlaying,
	})
}
Esempio n. 2
0
func (e *Engine) sendIdentity(device *network.Device) error {
	return device.Send(protocol.IdentityType, &protocol.Identity{
		DeviceId:        e.config.DeviceId,
		DeviceName:      e.config.DeviceName,
		ProtocolVersion: protocol.Version,
		DeviceType:      e.config.DeviceType,
		TcpPort:         e.config.TcpPort,
	})
}
Esempio n. 3
0
func (e *Engine) PairDevice(device *network.Device) error {
	if device.Paired {
		return nil
	}

	if !device.PairRequestSent {
		pair := &protocol.Pair{
			Pair: true,
		}

		pub, err := e.config.PrivateKey.PublicKey().Marshal()
		if err != nil {
			return err
		}
		pair.PublicKey = string(pub)

		err = device.Send(protocol.PairType, pair)
		if err != nil {
			return err
		}

		log.Println("Sent pairing request to", device.Name)

		device.PairRequestSent = true
	}

	if device.PairRequestReceived && device.PairRequestSent {
		device.Paired = true

		log.Println("Device", device.Name, "paired")

		if e.getKnownDevice(device) == -1 {
			// Add it to the list of known devices
			e.config.KnownDevices = append(e.config.KnownDevices, NewKnownDeviceFromDevice(device))
		}

		select {
		case e.Paired <- device:
		default:
		}
	}

	return nil
}
Esempio n. 4
0
func (e *Engine) UnpairDevice(device *network.Device) error {
	if device.Paired {
		err := device.Send(protocol.PairType, &protocol.Pair{
			Pair: false,
		})
		if err != nil {
			return err
		}

		device.Paired = false
	}

	select {
	case e.Unpaired <- device:
	default:
	}

	return nil
}
Esempio n. 5
0
func (p *Ping) SendPing(device *network.Device) error {
	return device.Send(PingType, nil)
}
Esempio n. 6
0
func (p *Mpris) SendSeek(device *network.Device, seek float64) error {
	return device.Send(MprisType, &MprisBody{
		Seek: seek,
	})
}
Esempio n. 7
0
func (p *Mpris) SendSetPosition(device *network.Device, position float64) error {
	return device.Send(MprisType, &MprisBody{
		SetPosition: position,
	})
}
Esempio n. 8
0
func (p *Mpris) SendSetVolume(device *network.Device, volume int) error {
	return device.Send(MprisType, &MprisBody{
		SetVolume: volume,
	})
}
Esempio n. 9
0
func (p *Mpris) SendAction(device *network.Device, action string) error {
	return device.Send(MprisType, &MprisBody{Action: action})
}
Esempio n. 10
0
func (p *Mpris) SendPlayerList(device *network.Device, playerList []string) error {
	return device.Send(MprisType, &MprisBody{PlayerList: playerList})
}
Esempio n. 11
0
func (p *Battery) SendRequest(device *network.Device) error {
	return device.Send(BatteryType, &BatteryBody{Request: true})
}
Esempio n. 12
0
func (p *Notification) SendRequest(device *network.Device) error {
	return device.Send(NotificationType, &NotificationBody{Request: true})
}
Esempio n. 13
0
func (p *Sftp) SendStartBrowsing(device *network.Device) error {
	return device.Send(SftpType, &SftpBody{StartBrowsing: true})
}