Tham chiếu API

Ghép đôi

Kiểm tra app.capabilities để biết tính năng và app.access cùng quyền máy chủ để xác định quyền truy cập. Thay giá trị mẫu trước khi gọi.

Device A
plainapp://pair?request=<URL-encoded JSON>
Device B

QR

QR payload

QR: A hiển thị, B quét. c-id LAN xác định bên gửi; BLE dùng kênh truyền riêng. PAIR_CANCEL là tùy chọn.

Di chuột hoặc chạm một trường
1 / 2

Ảnh chụp giả lập tại thời điểm cố định; chữ ký và requestIds khớp. 192.0.2.0/24 dành riêng cho tài liệu. 8443 là cổng HTTPS mặc định; dùng cổng khám phá được trong yêu cầu thật. Các yêu cầu giới hạn thời gian này không thể phát lại nguyên dạng.

Trong PlainApp Desktop, trước khi quản lý thiết bị mới hoặc thiết bị đã đổi khóa công khai, hãy xác nhận rõ rằng bạn tin cậy thiết bị đó. Bước này không hiện mã đối chiếu và sẽ cảnh báo nếu khóa đã thay đổi. Nếu không dùng mật khẩu, hãy đối chiếu mã hiển thị trên cả hai thiết bị rồi mới chấp thuận trên thiết bị còn lại. Khi xác thực bằng mật khẩu, thiết bị còn lại vẫn có thể yêu cầu chấp thuận mà không hiện mã.

Định nghĩa kiểu

graphql
type Subscription {
  peersChanged: Boolean!
  pairingRequested: PairingRequestNotice!
  pairingCompleted: PairingCompletedNotice!
  pairingStarted: PairingProgressNotice!
  pairingFailed: PairingProgressNotice!
  pairingCanceled: PairingProgressNotice!
}

type Mutation {
  cancelPairing(peerId: ID!): Boolean!
  deletePeer(peerId: ID!): Boolean!
  pairPeer(peerId: ID!, input: PairPeerInput!): Boolean!
  respondToPairing(peerId: ID!, accepted: Boolean!): Boolean!
  unpairPeer(peerId: ID!): Boolean!
}

type Query {
  peerFileUrl(peerId: ID!, fileId: String!): String!
  peers: [Peer!]!
}

enum DeviceType {
	COMPUTER
	PHONE
	TABLET
	TV
	NAS
	OTHER
}

scalar Instant

input PairPeerInput {
	mode: PairingMode!
	password: String
}

type PairingCompletedNotice {
	deviceId: ID!
	deviceName: String!
	ip: String!
	port: Int
	deviceType: DeviceType
	requestId: String
}

enum PairingErrorCode {
	TIMEOUT
	REJECTED
	PASSWORD_REQUIRED
	INVALID_PASSWORD
	PEER_IDENTITY_CHANGED
	TOO_MANY_LOGIN_ATTEMPTS
	INTERNAL_ERROR
}

enum PairingMode {
	CHAT
	MANAGE
}

type PairingProgressNotice {
	verificationCode: String
	deviceId: ID!
	deviceName: String!
	error: PairingErrorCode
}

type PairingRequestNotice {
	fromIp: String!
	fromId: ID!
	fromName: String!
	deviceType: DeviceType!
	verificationCode: String!
	identityChanged: Boolean!
}

type Peer {
	id: ID!
	name: String!
	ip: String!
	status: PeerStatus!
	port: Int
	deviceType: DeviceType!
	createdAt: Instant!
	updatedAt: Instant!
	online: Boolean!
	managed: Boolean!
	key: String!
	publicKey: String!
	token: String!
}

enum PeerStatus {
	PAIRED
	UNPAIRED
	CHANNEL
}

Thao tác

subscription

peersChanged

Nhận tín hiệu khi bản ghi thiết bị ngang hàng thay đổi.

graphql
subscription peersChanged {
  peersChanged
}
subscription

pairingRequested

Nhận yêu cầu ghép đôi đến đang chờ quyết định.

graphql
subscription pairingRequested {
  pairingRequested { fromIp fromId fromName deviceType verificationCode identityChanged }
}
subscription

pairingCompleted

Nhận thông báo ghép đôi thiết bị hoàn tất.

graphql
subscription pairingCompleted {
  pairingCompleted { deviceId deviceName ip port deviceType requestId }
}
subscription

pairingStarted

Nhận thông báo bắt đầu lần ghép đôi.

graphql
subscription pairingStarted {
  pairingStarted { verificationCode deviceId deviceName error }
}
subscription

pairingFailed

Nhận thông báo lần ghép đôi thất bại.

graphql
subscription pairingFailed {
  pairingFailed { verificationCode deviceId deviceName error }
}
subscription

pairingCanceled

Nhận thông báo lần ghép đôi bị hủy.

graphql
subscription pairingCanceled {
  pairingCanceled { verificationCode deviceId deviceName error }
}
mutation

cancelPairing

Hủy ghép nối đang diễn ra của thiết bị được chỉ định.

graphql
mutation cancelPairing($peerId: ID!) {
  cancelPairing(peerId: $peerId)
}
mutation

deletePeer

Xóa thiết bị và lịch sử trò chuyện riêng; giữ bản ghi nếu kênh vẫn tham chiếu đến thiết bị.

graphql
mutation deletePeer($peerId: ID!) {
  deletePeer(peerId: $peerId)
}
mutation

pairPeer

Bắt đầu ghép nối trò chuyện hoặc đăng nhập quản lý; true cho biết yêu cầu đã được tiếp nhận.

graphql
mutation pairPeer($peerId: ID!, $input: PairPeerInput!) {
  pairPeer(peerId: $peerId, input: $input)
}
mutation

respondToPairing

Chấp nhận hoặc từ chối yêu cầu ghép nối hay xác nhận tin cậy đang chờ của thiết bị.

graphql
mutation respondToPairing($peerId: ID!, $accepted: Boolean!) {
  respondToPairing(peerId: $peerId, accepted: $accepted)
}
mutation

unpairPeer

Hủy ghép nối cục bộ và xóa quyền quản lý, giữ lại lịch sử trò chuyện.

graphql
mutation unpairPeer($peerId: ID!) {
  unpairPeer(peerId: $peerId)
}
query

peerFileUrl

Tạo URL tải tệp bằng địa chỉ hiện được lưu của thiết bị.

graphql
query peerFileUrl($peerId: ID!, $fileId: String!) {
  peerFileUrl(peerId: $peerId, fileId: $fileId)
}
query

peers

Liệt kê mọi thiết bị đã lưu, gồm đã ghép nối, chưa ghép nối và chỉ được kênh tham chiếu.

graphql
query peers {
  peers { id name ip status port deviceType createdAt updatedAt }
}