Skip to content

Commit

Permalink
feat: ✨ add parse room dynamic qrcode and join room by this qrcode (#79)
Browse files Browse the repository at this point in the history
* feat: ✨ add parse room dynamic qrcode and join room by this qrcode

* 1.0.102

* fix: 🐛 update grpc version

* fix: 🐛 typo
  • Loading branch information
su-chang authored Nov 15, 2024
1 parent 0426034 commit c1d1e73
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 3 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@juzi/wechaty-puppet-service",
"version": "1.0.101",
"version": "1.0.102",
"description": "Puppet Service for Wechaty",
"type": "module",
"exports": {
Expand Down Expand Up @@ -51,7 +51,7 @@
"@chatie/eslint-config": "^1.0.4",
"@chatie/semver": "^0.4.7",
"@chatie/tsconfig": "^4.6.3",
"@juzi/wechaty-puppet": "^1.0.92",
"@juzi/wechaty-puppet": "^1.0.93",
"@juzi/wechaty-puppet-mock": "^1.0.1",
"@swc/core": "1.3.39",
"@types/google-protobuf": "^3.15.5",
Expand All @@ -73,7 +73,7 @@
"@juzi/wechaty-puppet": "^1.0.84"
},
"dependencies": {
"@juzi/wechaty-grpc": "^1.0.87",
"@juzi/wechaty-grpc": "^1.0.89",
"clone-class": "^1.1.1",
"ducks": "^1.0.2",
"file-box": "^1.5.5",
Expand Down
37 changes: 37 additions & 0 deletions src/client/puppet-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1863,6 +1863,24 @@ class PuppetService extends PUPPET.Puppet {
return response.getQrcode()
}

override async roomParseDynamicQRCode (url: string): Promise<PUPPET.types.RoomParseDynamicQRCode> {
log.verbose('PuppetService', 'roomParseDynamicQRCode(%s)', url)

const request = new grpcPuppet.RoomParseDynamicQRCodeRequest()
request.setUrl(url)

const response = await util.promisify(
this.grpcManager.client.roomParseDynamicQRCode
.bind(this.grpcManager.client),
)(request)

return {
qrcode: response.getQrcode(),
qrcodeImgUrl: response.getQrcodeImageUrl(),
roomName: response.getRoomName(),
}
}

override async roomMemberList (roomId: string) : Promise<string[]> {
log.verbose('PuppetService', 'roomMemberList(%s)', roomId)

Expand Down Expand Up @@ -1998,6 +2016,25 @@ class PuppetService extends PUPPET.Puppet {
)(request)
}

override async roomInvitationAcceptByQRCode (
qrcode: string,
): Promise<PUPPET.types.RoomInvitationAcceptByQRCode> {
log.verbose('PuppetService', 'roomInvitationAcceptByQRCode(%s)', qrcode)

const request = new grpcPuppet.RoomInvitationAcceptByQRCodeRequest()
request.setQrcode(qrcode)

const response = await util.promisify(
this.grpcManager.client.roomInvitationAcceptByQRCode
.bind(this.grpcManager.client),
)(request)

return {
roomId: response.getRoomId(),
chatId: response.getChatId(),
}
}

override async roomInvitationRawPayload (
id: string,
): Promise<PUPPET.payloads.RoomInvitation> {
Expand Down
39 changes: 39 additions & 0 deletions src/server/puppet-implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1503,6 +1503,25 @@ function puppetImplementation (
}
},

roomInvitationAcceptByQRCode: async (call, callback) => {
log.verbose('PuppetServiceImpl', 'roomInvitationAcceptByQRCode()')

try {
const qrcode = call.request.getQrcode()

const result = await puppet.roomInvitationAcceptByQRCode(qrcode)

const response = new grpcPuppet.RoomInvitationAcceptByQRCodeResponse()
response.setRoomId(result.roomId)
response.setChatId(result.chatId)

return callback(null, response)

} catch (e) {
return grpcError('roomInvitationAccept', e, callback)
}
},

roomInvitationPayload: async (call, callback) => {
log.verbose('PuppetServiceImpl', 'roomInvitationPayload()')

Expand Down Expand Up @@ -1681,6 +1700,26 @@ function puppetImplementation (
}
},

roomParseDynamicQRCode: async (call, callback) => {
log.verbose('PuppetServiceImpl', 'roomParseDynamicQRCode()')

try {
const url = call.request.getUrl()

const qrcodeInfo = await puppet.roomParseDynamicQRCode(url)

const response = new grpcPuppet.RoomParseDynamicQRCodeResponse()
response.setQrcode(qrcodeInfo.qrcode)
response.setQrcodeImageUrl(qrcodeInfo.qrcodeImgUrl)
response.setRoomName(qrcodeInfo.roomName)

return callback(null, response)

} catch (e) {
return grpcError('roomParseDynamicQRCode', e, callback)
}
},

roomQuit: async (call, callback) => {
log.verbose('PuppetServiceImpl', 'roomQuit()')

Expand Down

0 comments on commit c1d1e73

Please sign in to comment.