@7365admin1/layer-common 3.2.1-staging.72 → 3.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/components/EntryPassInformation.vue +4 -4
- package/components/FeedbackMain.vue +7 -7
- package/components/HidAccessLogDashboard.vue +44 -119
- package/components/HidIdentityMapping.vue +975 -0
- package/components/HidIntercomManagement.vue +201 -808
- package/components/HidQrCodeConfiguration.vue +95 -907
- package/components/HidServiceSettingsPanel.vue +1 -20
- package/components/HidUserEnrollment.vue +81 -392
- package/components/Layout/NavigationDrawer.vue +2 -43
- package/components/NavigationItem.vue +0 -9
- package/components/Nfc/NFCPatrolRouteMain.vue +7 -52
- package/components/OnlineFormConfigurationForm.vue +224 -620
- package/components/OnlineFormFill.vue +8 -36
- package/components/OnlineFormsConfiguration.vue +2 -6
- package/components/QrTemplate/CreditCardLandscape.vue +12 -19
- package/components/QrTemplate/PrintDialog.vue +196 -209
- package/components/SiteSettings.vue +2 -4
- package/components/VisitorForm.vue +78 -201
- package/components/VisitorManagement.vue +2 -1
- package/components/VisitorSocketPopUp.vue +2 -56
- package/composables/useComment.ts +3 -3
- package/composables/useHidAmico.ts +0 -127
- package/composables/useHidNavigation.ts +7 -0
- package/composables/useOnlineFormPages.ts +0 -2
- package/composables/useSiteSettings.ts +0 -50
- package/composables/useVisitorSocket.ts +0 -26
- package/composables/useWebUsb.ts +37 -127
- package/middleware/member.ts +4 -0
- package/package.json +1 -3
- package/pages/[org]/[site]/access-mgmt/identity-mapping/index.vue +23 -0
- package/pages/[org]/[site]/access-mgmt/intercom/index.vue +1 -1
- package/plugins/secure-member.client.ts +56 -21
- package/plugins/vuetify.ts +9 -37
- package/types/site.d.ts +0 -71
- package/.changeset/camera-wall-gated-endpoint.md +0 -47
- package/.changeset/camera-wall-plain-english.md +0 -60
- package/.changeset/camera-wall-selection-and-guidance.md +0 -65
- package/.changeset/dark-primary-contrast.md +0 -39
- package/components/CameraWall.vue +0 -1034
- package/components/CameraWallTile.vue +0 -818
- package/components/HidCameraCaptureDialog.vue +0 -199
- package/composables/useSipWebPhone.ts +0 -311
- package/test/visitor-socket.test.mjs +0 -36
- package/utils/camera-wall.test.ts +0 -571
- package/utils/camera-wall.ts +0 -926
- package/utils/theme.test.ts +0 -201
- package/utils/theme.ts +0 -136
|
@@ -28,46 +28,6 @@ type HidIdentityPayload = {
|
|
|
28
28
|
metadata?: Record<string, any>;
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
type HidVisitorQrData = {
|
|
32
|
-
visitorId: string;
|
|
33
|
-
readerId: string;
|
|
34
|
-
hidUserId: number;
|
|
35
|
-
qrValue: string;
|
|
36
|
-
qrFormat: "0" | "1" | "2";
|
|
37
|
-
issuedAt: string;
|
|
38
|
-
expiresAt: string;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
type HidVisitorQrResponse = HidVisitorQrData | { data: HidVisitorQrData };
|
|
42
|
-
|
|
43
|
-
type HidPermissionListResponse = {
|
|
44
|
-
items: THidPermissionCandidate[];
|
|
45
|
-
page: number;
|
|
46
|
-
pages: number;
|
|
47
|
-
pageRange: string;
|
|
48
|
-
limit: number;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
type HidFacialEnrollmentResult = {
|
|
52
|
-
user_id?: number;
|
|
53
|
-
success?: boolean;
|
|
54
|
-
scores?: Record<string, unknown>;
|
|
55
|
-
errors?: Array<{ code?: number; message?: string }>;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export type HidSipAccountData = {
|
|
59
|
-
orgId: string;
|
|
60
|
-
site: string;
|
|
61
|
-
userId: string;
|
|
62
|
-
extension: string;
|
|
63
|
-
username: string;
|
|
64
|
-
password: string;
|
|
65
|
-
sipAddress: string;
|
|
66
|
-
websocketUrl: string;
|
|
67
|
-
status: "active";
|
|
68
|
-
provisionedAt: string;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
31
|
export default function useHidAmico() {
|
|
72
32
|
const basePath = "/api/access-management/hid";
|
|
73
33
|
|
|
@@ -118,16 +78,6 @@ export default function useHidAmico() {
|
|
|
118
78
|
});
|
|
119
79
|
}
|
|
120
80
|
|
|
121
|
-
function issueVisitorQr(
|
|
122
|
-
readerId: string,
|
|
123
|
-
payload: { visitorId: string; validityMinutes: number; qrFormat: "0" | "1" | "2" },
|
|
124
|
-
) {
|
|
125
|
-
return useNuxtApp().$api<HidVisitorQrResponse>(`${basePath}/readers/${readerId}/visitor-qr`, {
|
|
126
|
-
method: "POST",
|
|
127
|
-
body: payload,
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
|
|
131
81
|
function getReaderConfiguration(readerId: string, payload: Record<string, string[]> = {}) {
|
|
132
82
|
return useNuxtApp().$api<Record<string, any>>(`${basePath}/readers/${readerId}/configuration`, {
|
|
133
83
|
method: "POST",
|
|
@@ -162,33 +112,6 @@ export default function useHidAmico() {
|
|
|
162
112
|
});
|
|
163
113
|
}
|
|
164
114
|
|
|
165
|
-
function setUserImage(
|
|
166
|
-
readerId: string,
|
|
167
|
-
hidUserId: string | number,
|
|
168
|
-
image: Blob,
|
|
169
|
-
options: { timestamp?: number; match?: boolean } = {},
|
|
170
|
-
) {
|
|
171
|
-
return useNuxtApp().$api<{ data: HidFacialEnrollmentResult }>(
|
|
172
|
-
`${basePath}/readers/${readerId}/users/${hidUserId}/image`,
|
|
173
|
-
{
|
|
174
|
-
method: "PUT",
|
|
175
|
-
query: {
|
|
176
|
-
...(options.timestamp ? { timestamp: options.timestamp } : {}),
|
|
177
|
-
match: options.match ?? true,
|
|
178
|
-
},
|
|
179
|
-
headers: { "Content-Type": "application/octet-stream" },
|
|
180
|
-
body: image,
|
|
181
|
-
},
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
function deleteUserImage(readerId: string, hidUserId: string | number) {
|
|
186
|
-
return useNuxtApp().$api<Record<string, unknown>>(
|
|
187
|
-
`${basePath}/readers/${readerId}/users/${hidUserId}/image`,
|
|
188
|
-
{ method: "DELETE" },
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
115
|
function createIdentity(readerId: string, payload: HidIdentityPayload) {
|
|
193
116
|
return useNuxtApp().$api<Record<string, any>>(`${basePath}/readers/${readerId}/identities`, {
|
|
194
117
|
method: "POST",
|
|
@@ -228,49 +151,6 @@ export default function useHidAmico() {
|
|
|
228
151
|
});
|
|
229
152
|
}
|
|
230
153
|
|
|
231
|
-
function getSitePermissions(siteId: string, orgId: string, readerId: string) {
|
|
232
|
-
return useNuxtApp().$api<{ data: THidSitePermissions }>(
|
|
233
|
-
`${basePath}/sites/${siteId}/permissions`,
|
|
234
|
-
{ method: "GET", query: { orgId, readerId } },
|
|
235
|
-
);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
function ensureSipAccount(siteId: string, orgId: string) {
|
|
239
|
-
return useNuxtApp().$api<{ data: HidSipAccountData }>(
|
|
240
|
-
`${basePath}/sites/${siteId}/intercom/sip-account`,
|
|
241
|
-
{ method: "POST", body: { orgId } },
|
|
242
|
-
);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
function getPermissionCandidates(
|
|
246
|
-
siteId: string,
|
|
247
|
-
query: {
|
|
248
|
-
orgId: string;
|
|
249
|
-
readerId: string;
|
|
250
|
-
category: THidPermissionCategory | "intercom";
|
|
251
|
-
search?: string;
|
|
252
|
-
page?: number;
|
|
253
|
-
limit?: number;
|
|
254
|
-
},
|
|
255
|
-
) {
|
|
256
|
-
return useNuxtApp().$api<HidPermissionListResponse>(
|
|
257
|
-
`${basePath}/sites/${siteId}/permission-candidates`,
|
|
258
|
-
{ method: "GET", query },
|
|
259
|
-
);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
function updateSitePermissions(
|
|
263
|
-
siteId: string,
|
|
264
|
-
orgId: string,
|
|
265
|
-
readerId: string,
|
|
266
|
-
assignments: Array<Pick<THidPermissionAssignment, "subjectId" | "category" | "intercom">>,
|
|
267
|
-
) {
|
|
268
|
-
return useNuxtApp().$api<{ data: THidSitePermissions; message: string }>(
|
|
269
|
-
`${basePath}/sites/${siteId}/permissions`,
|
|
270
|
-
{ method: "PUT", body: { orgId, readerId, assignments } },
|
|
271
|
-
);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
154
|
return {
|
|
275
155
|
getReaders,
|
|
276
156
|
createReader,
|
|
@@ -279,13 +159,10 @@ export default function useHidAmico() {
|
|
|
279
159
|
testReader,
|
|
280
160
|
syncReader,
|
|
281
161
|
runObjectOperation,
|
|
282
|
-
issueVisitorQr,
|
|
283
162
|
getReaderConfiguration,
|
|
284
163
|
setReaderConfiguration,
|
|
285
164
|
getLogs,
|
|
286
165
|
getUserImage,
|
|
287
|
-
setUserImage,
|
|
288
|
-
deleteUserImage,
|
|
289
166
|
getIdentities,
|
|
290
167
|
createIdentity,
|
|
291
168
|
updateIdentity,
|
|
@@ -293,9 +170,5 @@ export default function useHidAmico() {
|
|
|
293
170
|
getIntercomStatus,
|
|
294
171
|
makeIntercomCall,
|
|
295
172
|
finalizeIntercomCall,
|
|
296
|
-
ensureSipAccount,
|
|
297
|
-
getSitePermissions,
|
|
298
|
-
getPermissionCandidates,
|
|
299
|
-
updateSitePermissions,
|
|
300
173
|
};
|
|
301
174
|
}
|
|
@@ -41,6 +41,13 @@ export default function useHidNavigation() {
|
|
|
41
41
|
params: { org, site },
|
|
42
42
|
},
|
|
43
43
|
},
|
|
44
|
+
{
|
|
45
|
+
title: "Identity Mapping",
|
|
46
|
+
route: {
|
|
47
|
+
name: "org-site-access-mgmt-identity-mapping",
|
|
48
|
+
params: { org, site },
|
|
49
|
+
},
|
|
50
|
+
},
|
|
44
51
|
{
|
|
45
52
|
title: "Access Logs",
|
|
46
53
|
route: {
|
|
@@ -20,8 +20,6 @@ export type FormBlock =
|
|
|
20
20
|
| { type: "checkbox-group"; title?: string; single?: boolean; items: CheckboxItemDef[] }
|
|
21
21
|
| { type: "paragraph"; text: string }
|
|
22
22
|
| { type: "section-header"; text: string }
|
|
23
|
-
| { type: "ordered-list"; title?: string; items: string[] }
|
|
24
|
-
| { type: "unordered-list"; title?: string; items: string[] }
|
|
25
23
|
| { type: "divider" }
|
|
26
24
|
| { type: "signature-row"; label: string; key: string }
|
|
27
25
|
| { type: "acknowledgement"; text: string }
|
|
@@ -99,54 +99,6 @@ export default function () {
|
|
|
99
99
|
});
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
/**
|
|
103
|
-
* The monitoring wall for one site.
|
|
104
|
-
*
|
|
105
|
-
* A different endpoint from `getAllSiteCameras`, and the difference is the
|
|
106
|
-
* point. That one is the Settings panel's paginated CRUD list; this one is
|
|
107
|
-
* purpose-built for a wall and is what the React Native app already uses:
|
|
108
|
-
*
|
|
109
|
-
* - it is **site-scoped and authorised server-side** — the caller must be a
|
|
110
|
-
* member of the site, of its owning organisation, or work for an
|
|
111
|
-
* organisation engaged to serve it;
|
|
112
|
-
* - it returns `type: "ip"` cameras only, so an ANPR unit can never land on a
|
|
113
|
-
* monitoring wall;
|
|
114
|
-
* - it returns each camera's **capability descriptor** and the server's own
|
|
115
|
-
* `unavailableReason`, so a tile explains itself instead of showing a black
|
|
116
|
-
* rectangle;
|
|
117
|
-
* - it never returns a credential, and it contacts no device.
|
|
118
|
-
*
|
|
119
|
-
* Unpaginated by design: a wall shows a site's cameras, and paging them was
|
|
120
|
-
* an artefact of borrowing the CRUD list.
|
|
121
|
-
*/
|
|
122
|
-
async function getSiteWall(siteId: string) {
|
|
123
|
-
return await useNuxtApp().$api<Record<string, any>>(
|
|
124
|
-
`/api/site-cameras/site/${siteId}/wall`,
|
|
125
|
-
{ method: "GET" }
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Health for the cameras currently on screen.
|
|
131
|
-
*
|
|
132
|
-
* Same site scoping as the wall, and the ids are narrowed to the visible
|
|
133
|
-
* tiles on purpose: this is the one camera call that can reach a device, and
|
|
134
|
-
* asking about cameras nobody is looking at spends a real budget for nothing.
|
|
135
|
-
*
|
|
136
|
-
* **Reachability is answered per RECORDER and cached there**, so a wall of
|
|
137
|
-
* twelve channels on one device is one connect rather than twelve, and
|
|
138
|
-
* several supervisors watching the same wall is still one. That is what makes
|
|
139
|
-
* it safe to ask on a timer at all — but only a slow one: the server caches
|
|
140
|
-
* for `healthCacheSeconds`, and asking faster than the cache buys nothing and
|
|
141
|
-
* costs round trips.
|
|
142
|
-
*/
|
|
143
|
-
async function getSiteHealth(siteId: string, cameraIds: string[]) {
|
|
144
|
-
return await useNuxtApp().$api<Record<string, any>>(
|
|
145
|
-
`/api/site-cameras/site/${siteId}/health`,
|
|
146
|
-
{ method: "GET", query: { ids: cameraIds.join(",") } }
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
102
|
async function updateSiteInformation(
|
|
151
103
|
siteId: string,
|
|
152
104
|
payload: { bgImage: string; description: string; docs: { id: string; name: string }[] }
|
|
@@ -223,8 +175,6 @@ export default function () {
|
|
|
223
175
|
updateSite,
|
|
224
176
|
addCamera,
|
|
225
177
|
getAllSiteCameras,
|
|
226
|
-
getSiteWall,
|
|
227
|
-
getSiteHealth,
|
|
228
178
|
setSiteGuardPosts,
|
|
229
179
|
updateSiteCamera,
|
|
230
180
|
deleteSiteCameraById,
|
|
@@ -5,32 +5,6 @@ export type TVisitorSocketData = {
|
|
|
5
5
|
message?: string;
|
|
6
6
|
messagePermanent?: string;
|
|
7
7
|
reload?: boolean;
|
|
8
|
-
/**
|
|
9
|
-
* Camera health. Sent alongside `message` by API-core so the client can group
|
|
10
|
-
* or clear an alert per camera instead of matching on the message text.
|
|
11
|
-
* Absent on older API-core builds — treat a bare `message` as a fault.
|
|
12
|
-
*/
|
|
13
|
-
event?: "camera-fault" | "camera-recovered";
|
|
14
|
-
/** The camera the `event` is about. */
|
|
15
|
-
camera?: string;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* One line for however many cameras are currently down.
|
|
20
|
-
*
|
|
21
|
-
* A site with several ANPR cameras could otherwise raise one alert per camera
|
|
22
|
-
* at the same moment. The single-camera case shows the server's own message,
|
|
23
|
-
* which names the camera; beyond that, naming them all in a snackbar is worse
|
|
24
|
-
* than sending the operator to the page that lists them.
|
|
25
|
-
*/
|
|
26
|
-
export const cameraAlertMessage = (messages: string[]): string => {
|
|
27
|
-
if (!messages.length) return "";
|
|
28
|
-
if (messages.length === 1) return messages[0] as string;
|
|
29
|
-
return (
|
|
30
|
-
`${messages.length} cameras at this site are not responding. Plate reads ` +
|
|
31
|
-
`and automatic barrier opening are stopped for them. Open Site Settings > ` +
|
|
32
|
-
`Cameras to see which.`
|
|
33
|
-
);
|
|
34
8
|
};
|
|
35
9
|
|
|
36
10
|
export const useVisitorSocket = () => {
|
package/composables/useWebUsb.ts
CHANGED
|
@@ -11,10 +11,6 @@ interface USBDevice {
|
|
|
11
11
|
close(): Promise<void>;
|
|
12
12
|
selectConfiguration(configurationValue: number): Promise<void>;
|
|
13
13
|
claimInterface(interfaceNumber: number): Promise<void>;
|
|
14
|
-
selectAlternateInterface(
|
|
15
|
-
interfaceNumber: number,
|
|
16
|
-
alternateSetting: number,
|
|
17
|
-
): Promise<void>;
|
|
18
14
|
releaseInterface(interfaceNumber: number): Promise<void>;
|
|
19
15
|
transferOut(
|
|
20
16
|
endpointNumber: number,
|
|
@@ -23,27 +19,14 @@ interface USBDevice {
|
|
|
23
19
|
configuration: {
|
|
24
20
|
interfaces: Array<{
|
|
25
21
|
interfaceNumber: number;
|
|
26
|
-
alternate: USBAlternateInterface;
|
|
27
22
|
alternates: Array<{
|
|
28
|
-
alternateSetting: number;
|
|
29
|
-
interfaceClass: number;
|
|
30
23
|
endpoints: Array<{
|
|
31
24
|
endpointNumber: number;
|
|
32
25
|
direction: "in" | "out";
|
|
33
26
|
}>;
|
|
34
27
|
}>;
|
|
35
28
|
}>;
|
|
36
|
-
}
|
|
37
|
-
configurations: Array<{ configurationValue: number }>;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
interface USBAlternateInterface {
|
|
41
|
-
alternateSetting: number;
|
|
42
|
-
interfaceClass: number;
|
|
43
|
-
endpoints: Array<{
|
|
44
|
-
endpointNumber: number;
|
|
45
|
-
direction: "in" | "out";
|
|
46
|
-
}>;
|
|
29
|
+
};
|
|
47
30
|
}
|
|
48
31
|
|
|
49
32
|
interface USBOutTransferResult {
|
|
@@ -56,86 +39,13 @@ declare global {
|
|
|
56
39
|
usb: {
|
|
57
40
|
getDevices(): Promise<USBDevice[]>;
|
|
58
41
|
requestDevice(options: {
|
|
59
|
-
filters: Array<{
|
|
60
|
-
vendorId?: number;
|
|
61
|
-
productId?: number;
|
|
62
|
-
classCode?: number;
|
|
63
|
-
}>;
|
|
42
|
+
filters: Array<{ vendorId?: number; productId?: number }>;
|
|
64
43
|
}): Promise<USBDevice>;
|
|
65
44
|
};
|
|
66
45
|
}
|
|
67
46
|
}
|
|
68
47
|
|
|
69
48
|
export default function useWebUsb() {
|
|
70
|
-
const printerConnections = new WeakMap<
|
|
71
|
-
USBDevice,
|
|
72
|
-
{ interfaceNumber: number; endpointNumber: number }
|
|
73
|
-
>();
|
|
74
|
-
|
|
75
|
-
const protectedInterfaceClasses = new Set([0x01, 0x03, 0x08, 0x0b, 0x0e, 0x10, 0xe0]);
|
|
76
|
-
|
|
77
|
-
function getErrorMessage(error: unknown, fallback: string) {
|
|
78
|
-
return error instanceof Error && error.message ? error.message : fallback;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function findPrinterInterface(device: USBDevice) {
|
|
82
|
-
const candidates = (device.configuration?.interfaces || []).flatMap((usbInterface) =>
|
|
83
|
-
usbInterface.alternates.flatMap((alternate) => {
|
|
84
|
-
const outputEndpoint = alternate.endpoints.find((endpoint) => endpoint.direction === "out");
|
|
85
|
-
if (!outputEndpoint || protectedInterfaceClasses.has(alternate.interfaceClass)) return [];
|
|
86
|
-
|
|
87
|
-
return [{
|
|
88
|
-
interfaceNumber: usbInterface.interfaceNumber,
|
|
89
|
-
alternateSetting: alternate.alternateSetting,
|
|
90
|
-
activeAlternateSetting: usbInterface.alternate.alternateSetting,
|
|
91
|
-
interfaceClass: alternate.interfaceClass,
|
|
92
|
-
endpointNumber: outputEndpoint.endpointNumber,
|
|
93
|
-
}];
|
|
94
|
-
}),
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
candidates.sort((left, right) => {
|
|
98
|
-
const priority = (interfaceClass: number) => interfaceClass === 0x07 ? 0 : interfaceClass === 0xff ? 1 : 2;
|
|
99
|
-
return priority(left.interfaceClass) - priority(right.interfaceClass);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
return candidates[0] || null;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
async function preparePrinterDevice(device: USBDevice) {
|
|
106
|
-
await device.open();
|
|
107
|
-
if (!device.configuration) {
|
|
108
|
-
await device.selectConfiguration(device.configurations[0]?.configurationValue || 1);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const printerInterface = findPrinterInterface(device);
|
|
112
|
-
if (!printerInterface) {
|
|
113
|
-
throw new Error(
|
|
114
|
-
"The selected USB device is not a compatible printer. Select the receipt printer instead of a Bluetooth, camera, keyboard, or other system device.",
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
await device.claimInterface(printerInterface.interfaceNumber);
|
|
119
|
-
if (printerInterface.alternateSetting !== printerInterface.activeAlternateSetting) {
|
|
120
|
-
await device.selectAlternateInterface(
|
|
121
|
-
printerInterface.interfaceNumber,
|
|
122
|
-
printerInterface.alternateSetting,
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
printerConnections.set(device, {
|
|
127
|
-
interfaceNumber: printerInterface.interfaceNumber,
|
|
128
|
-
endpointNumber: printerInterface.endpointNumber,
|
|
129
|
-
});
|
|
130
|
-
return device;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function getPrinterConnection(device: USBDevice) {
|
|
134
|
-
const connection = printerConnections.get(device);
|
|
135
|
-
if (!connection) throw new Error("Printer interface is not connected");
|
|
136
|
-
return connection;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
49
|
const isWebUsbSupported = computed(() => {
|
|
140
50
|
return typeof navigator !== "undefined" && "usb" in navigator;
|
|
141
51
|
});
|
|
@@ -165,9 +75,7 @@ export default function useWebUsb() {
|
|
|
165
75
|
throw new Error("Web USB is not supported in this browser");
|
|
166
76
|
}
|
|
167
77
|
try {
|
|
168
|
-
const device = await navigator.usb.requestDevice({
|
|
169
|
-
filters: [{ classCode: 0x07 }, { classCode: 0xff }],
|
|
170
|
-
});
|
|
78
|
+
const device = await navigator.usb.requestDevice({ filters: [] });
|
|
171
79
|
return {
|
|
172
80
|
vendorId: device.vendorId,
|
|
173
81
|
productId: device.productId,
|
|
@@ -176,12 +84,12 @@ export default function useWebUsb() {
|
|
|
176
84
|
serialNumber: device.serialNumber || "Unknown",
|
|
177
85
|
deviceId: `${device.vendorId}:${device.productId}`,
|
|
178
86
|
};
|
|
179
|
-
} catch (error:
|
|
180
|
-
if (error
|
|
87
|
+
} catch (error: any) {
|
|
88
|
+
if (error.name === "NotFoundError") {
|
|
181
89
|
throw new Error("No device selected");
|
|
182
90
|
}
|
|
183
91
|
console.error("Error requesting USB device:", error);
|
|
184
|
-
throw new Error(
|
|
92
|
+
throw new Error("Failed to access USB device");
|
|
185
93
|
}
|
|
186
94
|
};
|
|
187
95
|
|
|
@@ -202,17 +110,14 @@ export default function useWebUsb() {
|
|
|
202
110
|
});
|
|
203
111
|
}
|
|
204
112
|
console.log("[WebUSB] Opening device:", device.vendorId, device.productId);
|
|
205
|
-
await
|
|
113
|
+
await device.open();
|
|
114
|
+
await device.selectConfiguration(1);
|
|
115
|
+
await device.claimInterface(0);
|
|
206
116
|
console.log("[WebUSB] Device opened and interface claimed.");
|
|
207
117
|
return device;
|
|
208
|
-
} catch (error
|
|
118
|
+
} catch (error) {
|
|
209
119
|
console.error("Error connecting to USB device:", error);
|
|
210
|
-
|
|
211
|
-
await device?.close();
|
|
212
|
-
} catch (closeError) {
|
|
213
|
-
console.error("Error closing rejected USB device:", closeError);
|
|
214
|
-
}
|
|
215
|
-
throw new Error(getErrorMessage(error, "Failed to connect to USB printer"));
|
|
120
|
+
throw new Error("Failed to connect to USB device");
|
|
216
121
|
}
|
|
217
122
|
};
|
|
218
123
|
|
|
@@ -268,20 +173,15 @@ export default function useWebUsb() {
|
|
|
268
173
|
? "Connection and print test successful"
|
|
269
174
|
: "Connection successful but print test failed",
|
|
270
175
|
};
|
|
271
|
-
} catch (error:
|
|
176
|
+
} catch (error: any) {
|
|
272
177
|
return {
|
|
273
178
|
success: false,
|
|
274
|
-
error:
|
|
179
|
+
error: error.message,
|
|
275
180
|
message: "Connection failed",
|
|
276
181
|
};
|
|
277
182
|
} finally {
|
|
278
183
|
if (device) {
|
|
279
184
|
try {
|
|
280
|
-
const connection = printerConnections.get(device);
|
|
281
|
-
if (connection) {
|
|
282
|
-
await device.releaseInterface(connection.interfaceNumber);
|
|
283
|
-
printerConnections.delete(device);
|
|
284
|
-
}
|
|
285
185
|
await device.close();
|
|
286
186
|
} catch (closeError) {
|
|
287
187
|
console.error("Error closing device:", closeError);
|
|
@@ -305,16 +205,21 @@ export default function useWebUsb() {
|
|
|
305
205
|
];
|
|
306
206
|
|
|
307
207
|
const testData = new Uint8Array(testCommands);
|
|
308
|
-
const
|
|
309
|
-
|
|
208
|
+
const usbInterface = device.configuration.interfaces[0];
|
|
209
|
+
const alternate = usbInterface.alternates[0];
|
|
210
|
+
const outputEndpoint = alternate.endpoints.find(
|
|
211
|
+
(ep: any) => ep.direction === "out",
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
if (!outputEndpoint) {
|
|
215
|
+
throw new Error("No output endpoint found");
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
await device.transferOut(outputEndpoint.endpointNumber, testData);
|
|
310
219
|
return { success: true, message: "Test print sent successfully" };
|
|
311
|
-
} catch (error:
|
|
220
|
+
} catch (error: any) {
|
|
312
221
|
console.error("Test print error:", error);
|
|
313
|
-
return {
|
|
314
|
-
success: false,
|
|
315
|
-
error: getErrorMessage(error, "Test print failed"),
|
|
316
|
-
message: "Test print failed",
|
|
317
|
-
};
|
|
222
|
+
return { success: false, error: error.message, message: "Test print failed" };
|
|
318
223
|
}
|
|
319
224
|
};
|
|
320
225
|
|
|
@@ -449,8 +354,13 @@ export default function useWebUsb() {
|
|
|
449
354
|
) => {
|
|
450
355
|
try {
|
|
451
356
|
console.log("[WebUSB] printQrCode start — doorLevel:", doorLevel, "liftLevel:", liftLevel, "company:", companyName, "address:", address);
|
|
452
|
-
const
|
|
453
|
-
|
|
357
|
+
const usbInterface = device.configuration.interfaces[0];
|
|
358
|
+
const alternate = usbInterface.alternates[0];
|
|
359
|
+
const outputEndpoint = alternate.endpoints.find(
|
|
360
|
+
(ep: any) => ep.direction === "out",
|
|
361
|
+
);
|
|
362
|
+
if (!outputEndpoint) throw new Error("No output endpoint found");
|
|
363
|
+
console.log("[WebUSB] Using endpoint:", outputEndpoint.endpointNumber);
|
|
454
364
|
|
|
455
365
|
const canvas = await createReceiptLayout(
|
|
456
366
|
urlImage,
|
|
@@ -465,17 +375,17 @@ export default function useWebUsb() {
|
|
|
465
375
|
const rasterData = canvasToRaster(canvas);
|
|
466
376
|
console.log("[WebUSB] Raster data size:", rasterData.byteLength, "bytes");
|
|
467
377
|
|
|
468
|
-
await device.transferOut(endpointNumber, rasterData.buffer);
|
|
378
|
+
await device.transferOut(outputEndpoint.endpointNumber, rasterData.buffer);
|
|
469
379
|
console.log("[WebUSB] Raster data sent.");
|
|
470
380
|
|
|
471
381
|
const CUT = new Uint8Array([0x1d, 0x56, 0x41, 0x10]);
|
|
472
|
-
await device.transferOut(endpointNumber, CUT.buffer);
|
|
382
|
+
await device.transferOut(outputEndpoint.endpointNumber, CUT.buffer);
|
|
473
383
|
console.log("[WebUSB] Cut command sent.");
|
|
474
384
|
|
|
475
385
|
return { success: true, message: "QR print sent successfully" };
|
|
476
|
-
} catch (error:
|
|
386
|
+
} catch (error: any) {
|
|
477
387
|
console.error("[WebUSB] printQrCode error:", error);
|
|
478
|
-
return { success: false, error:
|
|
388
|
+
return { success: false, error: error.message };
|
|
479
389
|
}
|
|
480
390
|
};
|
|
481
391
|
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@7365admin1/layer-common",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "3.2.1
|
|
5
|
+
"version": "3.2.1",
|
|
6
6
|
"author": "7365admin1",
|
|
7
7
|
"main": "./nuxt.config.ts",
|
|
8
8
|
"publishConfig": {
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
"build": "nuxt build .playground",
|
|
15
15
|
"generate": "nuxt generate .playground",
|
|
16
16
|
"preview": "nuxt preview .playground",
|
|
17
|
-
"test": "esbuild composables/useVisitorSocket.ts --format=esm --outfile=test/.build/useVisitorSocket.mjs --log-level=error && node --test \"test/*.test.mjs\"",
|
|
18
17
|
"release": "yarn run build && changeset publish"
|
|
19
18
|
},
|
|
20
19
|
"devDependencies": {
|
|
@@ -41,7 +40,6 @@
|
|
|
41
40
|
"qrcode": "^1.5.4",
|
|
42
41
|
"qrcode.vue": "^3.4.1",
|
|
43
42
|
"sass": "^1.80.6",
|
|
44
|
-
"sip.js": "0.21.2",
|
|
45
43
|
"socket.io-client": "^4.8.3",
|
|
46
44
|
"vue-draggable-next": "^2.3.0",
|
|
47
45
|
"vue3-signature": "^0.2.4",
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<v-container fluid>
|
|
3
|
+
<HidEnabledGate
|
|
4
|
+
:site="siteId"
|
|
5
|
+
:org="orgId"
|
|
6
|
+
message="Enable HID as a service for this site before mapping identities."
|
|
7
|
+
>
|
|
8
|
+
<HidIdentityMapping :site="siteId" :org="orgId" />
|
|
9
|
+
</HidEnabledGate>
|
|
10
|
+
</v-container>
|
|
11
|
+
</template>
|
|
12
|
+
|
|
13
|
+
<script setup lang="ts">
|
|
14
|
+
definePageMeta({
|
|
15
|
+
layout: "default",
|
|
16
|
+
middleware: ["01-auth", "02-org"],
|
|
17
|
+
memberOnly: true,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const route = useRoute();
|
|
21
|
+
const siteId = computed(() => String(route.params.site ?? ""));
|
|
22
|
+
const orgId = computed(() => String(route.params.org ?? ""));
|
|
23
|
+
</script>
|