feat: support socket room and add activity presence (#1445)
* feat: room init Signed-off-by: Innei <i@innei.in> * feat: web gateway hooks Signed-off-by: Innei <i@innei.in> * perf: debounce update event Signed-off-by: Innei <i@innei.in> * fix: socket online more accurate * fix: singleton * feat: add more hooks * fix: set metadata on socket * feat: api-client update Signed-off-by: Innei <i@innei.in> * update Signed-off-by: Innei <i@innei.in> * feat: add ip Signed-off-by: Innei <i@innei.in> * refactor: event Signed-off-by: Innei <i@innei.in> * fix: test Signed-off-by: Innei <i@innei.in> --------- Signed-off-by: Innei <i@innei.in>
This commit is contained in:
@@ -15,4 +15,39 @@ describe('test activity client', () => {
|
||||
client.activity.likeIt('Note', '11111111'),
|
||||
).resolves.not.toThrowError()
|
||||
})
|
||||
|
||||
test('GET /presence', async () => {
|
||||
mockResponse('/activity/presence', {
|
||||
s1122: {
|
||||
identity: 'user1',
|
||||
position: 0,
|
||||
ts: 123123123,
|
||||
},
|
||||
})
|
||||
|
||||
await expect(client.activity.getPresence('122')).resolves.not.toThrowError()
|
||||
})
|
||||
|
||||
test('POST /presence/update', async () => {
|
||||
mockResponse(
|
||||
'/activity/presence/update',
|
||||
{
|
||||
s1122: {
|
||||
identity: 'user1',
|
||||
position: 0,
|
||||
ts: 123123123,
|
||||
},
|
||||
},
|
||||
'post',
|
||||
)
|
||||
|
||||
await expect(
|
||||
client.activity.updatePresence({
|
||||
identity: 'user1',
|
||||
position: 2,
|
||||
roomName: '122',
|
||||
sid: 's-111',
|
||||
}),
|
||||
).resolves.not.toThrowError()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import type { IRequestAdapter } from '~/interfaces/adapter'
|
||||
import type { IController } from '~/interfaces/controller'
|
||||
import type { IRequestHandler } from '~/interfaces/request'
|
||||
import type { ActivityPresence } from '~/models/activity'
|
||||
import type { HTTPClient } from '../core'
|
||||
|
||||
import { autoBind } from '~/utils/auto-bind'
|
||||
|
||||
import { HTTPClient } from '../core'
|
||||
|
||||
declare module '../core/client' {
|
||||
interface HTTPClient<
|
||||
T extends IRequestAdapter = IRequestAdapter,
|
||||
@@ -38,4 +38,48 @@ export class ActivityController<ResponseWrapper> implements IController {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @support core >= 5.0.0
|
||||
*/
|
||||
getPresence(roomName: string) {
|
||||
return this.proxy.presence.get<Record<string, ActivityPresence>>({
|
||||
params: {
|
||||
room_name: roomName,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @support core >= 5.0.0
|
||||
*/
|
||||
updatePresence({
|
||||
identity,
|
||||
position,
|
||||
roomName,
|
||||
sid,
|
||||
|
||||
displayName,
|
||||
}: {
|
||||
roomName: string
|
||||
position: number
|
||||
identity: string
|
||||
sid: string
|
||||
|
||||
displayName?: string
|
||||
}) {
|
||||
return this.proxy.presence.update.post({
|
||||
data: {
|
||||
identity,
|
||||
position,
|
||||
ts: Date.now(),
|
||||
roomName,
|
||||
sid,
|
||||
|
||||
displayName,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
10
packages/api-client/models/activity.ts
Normal file
10
packages/api-client/models/activity.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
export interface ActivityPresence {
|
||||
operationTime: number
|
||||
updatedAt: number
|
||||
connectedAt: number
|
||||
identity: string
|
||||
roomName: string
|
||||
position: number
|
||||
|
||||
displayName?: string
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
export * from './activity'
|
||||
export * from './aggregate'
|
||||
export * from './base'
|
||||
export * from './category'
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@mx-space/api-client",
|
||||
"version": "1.7.2",
|
||||
"version": "1.8.0-alpha.4",
|
||||
"type": "module",
|
||||
"description": "A api client for mx-space server@next",
|
||||
"author": "Innei",
|
||||
@@ -60,4 +60,4 @@
|
||||
"vite": "^5.0.12",
|
||||
"vitest": "^1.0.4"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user