qshare

package module
v0.0.0-...-0d07254 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2025 License: Apache-2.0, MIT Imports: 1 Imported by: 0

README

go-qshare

codecov
GO library to communicate with devices via Quick Share protocol.

Requirements

To work with android devices (which is the main goal of this project) you need to enable experimental features for bluez. It can be done in bluetooth.service systemd service file. Just add --experimental to Exec.

How to use

Server
func main() {
    server, err := qserver.NewBuilder().
        WithDeviceType(qshare.LaptopDevice).
        Build(authCallback, textCallback, filesCallback)
    if err != nil {
        // ...
    }

    if err = server.Listen(); err != nil {
        // ...
    }

    // decide when to stop server by yourself
    if err = server.Stop(); err != nil {
        // ...
    }
}

func authCallback(text *qshare.TextMeta, files []qshare.FileMeta, pin uint16) bool {
    // print out pin and upcoming payloads here
    return true
}

func textCallback(payload qshare.TextPayload) {
    // do what you want with transferred text payload
}

func filesCallback(payload qshare.FilePayload) {
    var (
        n int
        err error
        chunkBuf = make([]byte, 512 * 1024)
    )

    for {
        n, err = payload.Pr.Read(chunkBuf)
        if err != nil {
            if errors.Is(err, io.EOF) {
                // success transfer, no data arrived, exit loop.
                break
            }
            // ...
        }
        // write chunkBuf somewhere
    }
}
Client

TODO

Test

make test

TODO

  • Refactor all TODOs in codebase
  • Add more tests
  • Client usage example in README
  • Security review
  • Security bot to keep track of vulnerabilities in dependent libs
  • Codebase statistics (lines of code / files / dependencies count)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthCallback

type AuthCallback func(text *TextMeta, files []FileMeta, pin uint16) bool

type DeviceType

type DeviceType uint
const (
	UnknownDevice DeviceType = iota
	PhoneDevice
	TabletDevice
	LaptopDevice
)

func (DeviceType) IsValid

func (t DeviceType) IsValid() bool

type FileCallback

type FileCallback func(payload FilePayload)

type FileMeta

type FileMeta struct {
	Type     FileType
	Name     string
	MimeType string
	Size     int64
}

type FilePayload

type FilePayload struct {
	Meta FileMeta
	Pr   *io.PipeReader
	Pw   *io.PipeWriter
}

type FileType

type FileType uint8
const (
	FileUnknown FileType = iota
	FileImage
	FileVideo
	FileApp
	FileAudio
)

type Logger

type Logger interface {
	Error(msg string, err error, args ...any)
	Warn(msg string, args ...any)
	Info(msg string, args ...any)
	Debug(msg string, args ...any)
}

type TextCallback

type TextCallback func(payload TextPayload)

type TextMeta

type TextMeta struct {
	Type  TextType
	Title string
	Size  int64
}

type TextPayload

type TextPayload struct {
	Meta TextMeta
	Text string
}

type TextType

type TextType uint8
const (
	TextUnknown TextType = iota
	TextText
	TextURL
	TextAddress
	TextPhoneNumber
)

func (TextType) IsUnknown

func (t TextType) IsUnknown() bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL