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