當前位置: 首頁>>代碼示例>>Golang>>正文


Golang network.Device類代碼示例

本文整理匯總了Golang中github.com/emersion/go-kdeconnect/network.Device的典型用法代碼示例。如果您正苦於以下問題:Golang Device類的具體用法?Golang Device怎麽用?Golang Device使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Device類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: SendRequest

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,
	})
}
開發者ID:emersion,項目名稱:go-kdeconnect,代碼行數:7,代碼來源:mpris.go

示例2: sendIdentity

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,
	})
}
開發者ID:emersion,項目名稱:go-kdeconnect,代碼行數:9,代碼來源:engine.go

示例3: PairDevice

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
}
開發者ID:emersion,項目名稱:go-kdeconnect,代碼行數:44,代碼來源:engine.go

示例4: UnpairDevice

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
}
開發者ID:emersion,項目名稱:go-kdeconnect,代碼行數:19,代碼來源:engine.go

示例5: SendPing

func (p *Ping) SendPing(device *network.Device) error {
	return device.Send(PingType, nil)
}
開發者ID:emersion,項目名稱:go-kdeconnect,代碼行數:3,代碼來源:ping.go

示例6: setDeviceIdentity

func setDeviceIdentity(device *network.Device, identity *protocol.Identity) {
	device.Id = identity.DeviceId
	device.Name = identity.DeviceName
	device.Type = identity.DeviceType
	device.ProtocolVersion = identity.ProtocolVersion
}
開發者ID:emersion,項目名稱:go-kdeconnect,代碼行數:6,代碼來源:engine.go

示例7: handleDevice

func (e *Engine) handleDevice(device *network.Device) {
	e.devices[device.Id] = device

	if i := e.getKnownDevice(device); i != -1 {
		device.Paired = true
		//device.PublicKey = e.config.KnownDevices[i].PublicKey
	}

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

	go device.Listen()
	go e.sendIdentity(device)

	for pkg := range device.Incoming {
		if pkg == nil {
			continue
		}

		// Decrypt package if encrypted
		if pkg.Type == protocol.EncryptedType {
			var err error
			pkg, err = pkg.Body.(*protocol.Encrypted).Decrypt(e.config.PrivateKey)
			if err != nil {
				log.Println("Cannot decrypt package:", err)
				continue
			}
		}

		if pkg.Type == protocol.PairType {
			pair := pkg.Body.(*protocol.Pair)

			if pair.Pair {
				// Remote asks pairing
				device.PairRequestReceived = true

				if len(pair.PublicKey) > 0 {
					// Remote sent its public key
					pub := &crypto.PublicKey{}

					if err := pub.Unmarshal([]byte(pair.PublicKey)); err != nil {
						log.Println("Cannot parse public key:", err)
						break
					}
					log.Println("Received public key")

					device.PublicKey = pub
				}

				if device.PairRequestSent {
					// We asked for pairing first, remote accepted
					log.Println("Device accepted pairing")

					e.PairDevice(device)
				} else {
					log.Println("Device requested pairing")

					select {
					case e.RequestsPairing <- device:
					default:
					}
				}
			} else {
				log.Println("Device requested unpairing")

				device.Paired = false
				e.UnpairDevice(device)
			}
		} else if pkg.Type == protocol.IdentityType {
			setDeviceIdentity(device, pkg.Body.(*protocol.Identity))
		} else {
			err := e.handler.Handle(device, pkg)
			if err != nil {
				log.Println("Error handling package:", err, pkg.Type, string(pkg.RawBody))
			}
		}
	}

	log.Println("Closed TCP connection")

	delete(e.devices, device.Id)

	select {
	case e.Leaves <- device:
	default:
	}
}
開發者ID:emersion,項目名稱:go-kdeconnect,代碼行數:89,代碼來源:engine.go

示例8: SendSeek

func (p *Mpris) SendSeek(device *network.Device, seek float64) error {
	return device.Send(MprisType, &MprisBody{
		Seek: seek,
	})
}
開發者ID:emersion,項目名稱:go-kdeconnect,代碼行數:5,代碼來源:mpris.go

示例9: SendSetPosition

func (p *Mpris) SendSetPosition(device *network.Device, position float64) error {
	return device.Send(MprisType, &MprisBody{
		SetPosition: position,
	})
}
開發者ID:emersion,項目名稱:go-kdeconnect,代碼行數:5,代碼來源:mpris.go

示例10: SendSetVolume

func (p *Mpris) SendSetVolume(device *network.Device, volume int) error {
	return device.Send(MprisType, &MprisBody{
		SetVolume: volume,
	})
}
開發者ID:emersion,項目名稱:go-kdeconnect,代碼行數:5,代碼來源:mpris.go

示例11: SendAction

func (p *Mpris) SendAction(device *network.Device, action string) error {
	return device.Send(MprisType, &MprisBody{Action: action})
}
開發者ID:emersion,項目名稱:go-kdeconnect,代碼行數:3,代碼來源:mpris.go

示例12: SendPlayerList

func (p *Mpris) SendPlayerList(device *network.Device, playerList []string) error {
	return device.Send(MprisType, &MprisBody{PlayerList: playerList})
}
開發者ID:emersion,項目名稱:go-kdeconnect,代碼行數:3,代碼來源:mpris.go

示例13: SendRequest

func (p *Battery) SendRequest(device *network.Device) error {
	return device.Send(BatteryType, &BatteryBody{Request: true})
}
開發者ID:emersion,項目名稱:go-kdeconnect,代碼行數:3,代碼來源:battery.go

示例14: SendRequest

func (p *Notification) SendRequest(device *network.Device) error {
	return device.Send(NotificationType, &NotificationBody{Request: true})
}
開發者ID:emersion,項目名稱:go-kdeconnect,代碼行數:3,代碼來源:notification.go

示例15: SendStartBrowsing

func (p *Sftp) SendStartBrowsing(device *network.Device) error {
	return device.Send(SftpType, &SftpBody{StartBrowsing: true})
}
開發者ID:emersion,項目名稱:go-kdeconnect,代碼行數:3,代碼來源:sftp.go


注:本文中的github.com/emersion/go-kdeconnect/network.Device類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。