@snap/push2web 0.11.0

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/LICENSE ADDED
@@ -0,0 +1,290 @@
1
+ The included software, associated documentation, software code, and other materials made available by Snap Inc. and its affiliates ("Snap") is Snap confidential information. Access to or use of the foregoing is subject to the Snap Developer Terms of Service, which you agree to and accept by downloading or installing the foregoing software, found at:
2
+
3
+ https://www.snap.com/terms/developer
4
+
5
+ If you no longer want to be a party to these terms or if you do not agree to all of these terms, then do not use or otherwise access the software, documentation, software code, and other materials, and notify Snap immediately.
6
+
7
+ ================================================================================
8
+ ================================================================================
9
+
10
+ Third-Party Software for Camera Kit Web
11
+
12
+ --------------------------------------------------------------------------------
13
+
14
+ The following 3rd-party software packages may be used by or distributed with Camera Kit Web. Any information relevant to third-party vendors listed below are collected using common, reasonable means.
15
+
16
+ Date generated: 2023-7-6
17
+
18
+ Revision ID: 1fff1bce68ca81ef935971d777c696c4d04e03bb
19
+
20
+ ================================================================================
21
+ ================================================================================
22
+
23
+
24
+
25
+
26
+
27
+ ================================================================================
28
+
29
+ Dependencies
30
+
31
+ ================================================================================
32
+
33
+ - @improbable-eng/grpc-web (0.15.0) [Apache-2.0]
34
+ - browser-headers (0.4.1) [Apache-2.0]
35
+ - long (4.0.0) [Apache-2.0]
36
+ - protobufjs (6.11.3) [BSD-3-Clause, MIT]
37
+ - rxjs (7.8.1) [Apache-2.0, 0BSD]
38
+
39
+
40
+ --------------------------------------------------------------------------------
41
+ Package Title: @improbable-eng/grpc-web (0.15.0)
42
+ --------------------------------------------------------------------------------
43
+
44
+ * Declared Licenses *
45
+ Apache-2.0
46
+
47
+
48
+ Copyright [yyyy] [name of copyright owner]
49
+
50
+ Licensed under the Apache License, Version 2.0 (the "License");
51
+ you may not use this file except in compliance with the License.
52
+ You may obtain a copy of the License at
53
+
54
+ http://www.apache.org/licenses/LICENSE-2.0
55
+
56
+ Unless required by applicable law or agreed to in writing, software
57
+ distributed under the License is distributed on an "AS IS" BASIS,
58
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
59
+
60
+ See the License for the specifi...
61
+
62
+
63
+ --------------------------------------------------------------------------------
64
+ Package Title: browser-headers (0.4.1)
65
+ --------------------------------------------------------------------------------
66
+
67
+ * Declared Licenses *
68
+ Apache-2.0
69
+
70
+
71
+ Apache License
72
+ Version 2.0, January 2004
73
+ http://www.apache.org/licenses/
74
+
75
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
76
+
77
+ 1. Definitions.
78
+
79
+ "License" shall mean the terms and conditions for use, reproduction,
80
+ and distribution as defined by Sections 1 through 9 of this document.
81
+
82
+ "Licensor" shall mean the copyright owner or entity authorized by
83
+ the copyright owner that ...
84
+
85
+
86
+ --------------------------------------------------------------------------------
87
+ Package Title: long (4.0.0)
88
+ --------------------------------------------------------------------------------
89
+
90
+ * Declared Licenses *
91
+ Apache-2.0
92
+
93
+
94
+
95
+ Apache License
96
+ Version 2.0, January 2004
97
+ http://www.apache.org/licenses/
98
+
99
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
100
+
101
+ 1. Definitions.
102
+
103
+ "License" shall mean the terms and conditions for use, reproduction,
104
+ and distribution as defined by Sections 1 through 9 of this document.
105
+
106
+ "Licensor" shall mean the copyright owner or entity authorized by
107
+ the copyri...
108
+
109
+
110
+ --------------------------------------------------------------------------------
111
+ Package Title: protobufjs (6.11.3)
112
+ --------------------------------------------------------------------------------
113
+
114
+ * Declared Licenses *
115
+ BSD-3-Clause
116
+
117
+
118
+ This license applies to all parts of protobuf.js except those files
119
+ either explicitly including or referencing a different license or
120
+ located in a directory containing a different LICENSE file.
121
+
122
+ ---
123
+
124
+ Copyright (c) 2016, Daniel Wirtz All rights reserved.
125
+
126
+ Redistribution and use in source and binary forms, with or without
127
+ modification, are permitted provided that the following conditions are
128
+ met:
129
+
130
+ * Redistributions of source code must retain the above copyright
131
+ notice, this list of condition...
132
+
133
+
134
+ * Other Licenses *
135
+ MIT
136
+
137
+
138
+ Copyright (c) 2016 Chad Engler
139
+ Permission is hereby granted, free of charge, to any person obtaining a copy
140
+ of this software and associated documentation files (the "Software"), to deal
141
+ in the Software without restriction, including without limitation the rights
142
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
143
+ copies of the Software, and to permit persons to whom the Software is
144
+ furnished to do so, subject to the following conditions:
145
+
146
+ The above copyright notice and t...
147
+
148
+
149
+ --------------------------------------------------------------------------------
150
+ Package Title: rxjs (7.8.1)
151
+ --------------------------------------------------------------------------------
152
+
153
+ * Declared Licenses *
154
+ Apache-2.0
155
+
156
+
157
+ Apache License
158
+ Version 2.0, January 2004
159
+ http://www.apache.org/licenses/
160
+
161
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
162
+
163
+ 1. Definitions.
164
+
165
+ "License" shall mean the terms and conditions for use, reproduction,
166
+ and distribution as defined by Sections 1 through 9 of this document.
167
+
168
+ "Licensor" shall mean the copyright owner or entity authorized by
169
+ the copyright owner that is granting the L...
170
+
171
+
172
+ * Other Licenses *
173
+ 0BSD
174
+
175
+
176
+ Copyright (C) 2006 by Rob Landley <rob@landley.net>
177
+ Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.
178
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA ...
179
+
180
+
181
+
182
+ ================================================================================
183
+ Licenses
184
+
185
+ ================================================================================
186
+
187
+ * Apache-2.0 *
188
+
189
+
190
+ Apache License
191
+ Version 2.0, January 2004
192
+ http://www.apache.org/licenses/
193
+
194
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
195
+
196
+ 1. Definitions.
197
+
198
+ "License" shall mean the terms and conditions for use, reproduction,
199
+ and distribution as defined by Sections 1 through 9 of this document.
200
+
201
+ "Licensor" shall mean the copyright owner or entity authorized by
202
+ the copyri...
203
+
204
+ * Apache-2.0 *
205
+
206
+ Apache License
207
+ Version 2.0, January 2004
208
+ http://www.apache.org/licenses/
209
+
210
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
211
+
212
+ 1. Definitions.
213
+
214
+ "License" shall mean the terms and conditions for use, reproduction,
215
+ and distribution as defined by Sections 1 through 9 of this document.
216
+
217
+ "Licensor" shall mean the copyright owner or entity authorized by
218
+ the copyright owner that ...
219
+
220
+ * Apache-2.0 *
221
+
222
+ Apache License
223
+ Version 2.0, January 2004
224
+ http://www.apache.org/licenses/
225
+
226
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
227
+
228
+ 1. Definitions.
229
+
230
+ "License" shall mean the terms and conditions for use, reproduction,
231
+ and distribution as defined by Sections 1 through 9 of this document.
232
+
233
+ "Licensor" shall mean the copyright owner or entity authorized by
234
+ the copyright owner that is granting the L...
235
+
236
+ * 0BSD *
237
+
238
+ Copyright (C) 2006 by Rob Landley <rob@landley.net>
239
+ Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.
240
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA ...
241
+
242
+ * Apache-2.0 *
243
+
244
+ Apache License
245
+ Version 2.0, January 2004
246
+ http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
247
+ 1. Definitions.
248
+
249
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
250
+
251
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
252
+
253
+ "Legal Entity" shall mean the union of the acting ...
254
+
255
+ * MIT *
256
+
257
+ MIT License
258
+ Copyright (c) <year> <copyright holders>
259
+
260
+ Permission is hereby granted, free of charge, to any person obtaining a copy
261
+ of this software and associated documentation files (the "Software"), to deal
262
+ in the Software without restriction, including without limitation the rights
263
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
264
+ copies of the Software, and to permit persons to whom the Software is
265
+ furnished to do so, subject to the following conditions:
266
+
267
+ The above...
268
+
269
+ * BSD-3-Clause *
270
+
271
+ This license applies to all parts of protobuf.js except those files
272
+ either explicitly including or referencing a different license or
273
+ located in a directory containing a different LICENSE file.
274
+
275
+ ---
276
+
277
+ Copyright (c) 2016, Daniel Wirtz All rights reserved.
278
+
279
+ Redistribution and use in source and binary forms, with or without
280
+ modification, are permitted provided that the following conditions are
281
+ met:
282
+
283
+ * Redistributions of source code must retain the above copyright
284
+ notice, this list of condition...
285
+
286
+
287
+ --------------------------------------------------------------------------------
288
+ --------------------------------------------------------------------------------
289
+
290
+ Report Generated by FOSSA on 2023-7-6
package/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # Snap Camera Kit Web SDK - Push to Web Extension
2
+
3
+ This extension for [Camera Kit Web SDK](https://www.npmjs.com/package/@snap/camera-kit) package, allows users to send lenses created in [Lens Studio](https://ar.snap.com/lens-studio) to their web pages. Simply create a lens in Lens Studio and then click the "Send to Camera Kit" button.
4
+
5
+ ## Prerequisites
6
+
7
+ Web pages should be integrated with Snap Login Kit in advance. This will allow users to sign in to your web page using their Snapchat account.
8
+
9
+ For quick integration, the Client-Side Only Web Application Integration method can be used. This method does not require any changes to the server-side code of your web page. Instead, it uses JavaScript to interact with the Snap Login Kit API.
10
+
11
+ ### !!! Important !!!
12
+ ```
13
+ !!! ONLY STAGING LOGIN KIT CLIENT ID IS SUPPORTED !!!
14
+ ```
15
+
16
+ [Login Kit](https://docs.snap.com/snap-kit/login-kit/Tutorials/web#requirements)
17
+
18
+ [Client-Side Only Web Application Integration](https://docs.snap.com/snap-kit/login-kit/Tutorials/web#client-side-only-web-application-integration)
19
+
20
+ ###
21
+
22
+ ## Getting started
23
+
24
+ ```
25
+ npm install @snap/push2web
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ Import the extension object from the package and create a new instance.
31
+ ```ts
32
+ import { Push2Web } from "@snap/push2web";
33
+
34
+ const push2Web = new Push2Web();
35
+ ```
36
+
37
+ The following events are available for subscription, if needed.
38
+ ```ts
39
+ push2Web.events.addEventListener("lensReceived", (event) => { const lensDetails = event.detail; });
40
+ push2Web.events.addEventListener("error", (event) => { const errorDetails = event.detail; });
41
+ push2Web.events.addEventListener("subscriptionChanged", (event) => { const subState = event.detail; };)
42
+ ```
43
+
44
+ Provide the push2web extension object during the Camera Kit bootstrap. It is essential to be familiar with the `@snap/camera-kit` package before using the `@snap/push2web` extension. Please find more details on [Camera Kit Web SDK documentation](https://docs.snap.com/camera-kit/quick-start/integrate-sdk/integrate-sdk-web/web-configuration) page.
45
+ ```ts
46
+ import { bootstrapCameraKit } from "@snap/camera-kit";
47
+
48
+ const extensions = (container) => container.provides(push2Web.extension);
49
+
50
+ const cameraKit = await bootstrapCameraKit({ apiToken: "token from developer portal" }, extensions);
51
+ const cameraKitSession = await cameraKit.createSession();
52
+ ```
53
+
54
+
55
+ Before pushing any lenses from Lens Studio, a subscription to a network stream must be established. Subscription should be created with the access token received after the user logs in to the web page using Login Kit integration.
56
+ ```ts
57
+ const loginKitAccessToken = "this token will be provided by Login Kit after user login";
58
+ const subscription = push2Web.subscribe(loginKitAccessToken, cameraKitSession, cameraKit.lensRepository);
59
+ ```
60
+
61
+ To unsubscribe from a stream, just call unsubscribe method on a subscription object.
62
+ ```ts
63
+ subscription.unsubscribe();
64
+ ```
65
+ ## Documentation
66
+
67
+ See https://docs.snap.com/camera-kit/quick-start/integrate-sdk/integrate-sdk-web/guides/push-2-web
@@ -0,0 +1,155 @@
1
+ import { Lens, CameraKit, CameraKitSession, TypedCustomEvent, TypedEventTarget } from "@snap/camera-kit";
2
+ import { ListenLensPushResponse_ExcludedLens_Code } from "./generated-api-client/camera_kit/v3/push_to_device";
3
+ import { Code } from "./generated-api-client/core/snap_status_code";
4
+ export declare class Push2Web {
5
+ /**
6
+ * Use this property to subscribe for the different types of events that can occur during push 2 web execution.
7
+ *
8
+ * Subscribe to `error` event to be aware if something has happened during the lens push,
9
+ * with network communication or any other type of error,
10
+ * event object also contains detailed expalantion of the cause.
11
+ *
12
+ * Use `subscriptionChanged` event to be aware when subscription state is changed.
13
+ *
14
+ * Use `lensReceived` event to be aware when new lens is received from Lens Studio,
15
+ * also you can get the additional details about the pushed lens.
16
+ *
17
+ * @example
18
+ *```ts
19
+ *push2web.events.addEventListener('error', ({ detail }) => {
20
+ * if (detail.name === 'LensExcludedError') {
21
+ * console.log(`Lens is excluded from the push, by the following reason: ${detail.reason}.`)
22
+ * }
23
+ *})
24
+ *```
25
+ */
26
+ readonly events: TypedEventTarget<Push2WebEvents>;
27
+ private readonly push2WebExtension;
28
+ private readonly pushedLenses;
29
+ private accesToken;
30
+ private subscription?;
31
+ /**
32
+ * Create new instance of Push2Web object,
33
+ * it can be used to start listening for the events,
34
+ * subscribe or unsubscribe for notifications from Lens Studio.
35
+ * Also provides the extension object for the @snap/camera-kit package.
36
+ */
37
+ constructor();
38
+ /**
39
+ * The extension object must be passed to the Camera Kit object during its bootstrap process.
40
+ * This is a requirement for the proper functioning of push to web functionality.
41
+ *
42
+ * @example
43
+ * ```ts
44
+ *import { bootstrapCameraKit } from "@snap/camera-kit";
45
+ *
46
+ *const push2web = new Push2Web();
47
+ *const extensions = (container) => container.provides(push2Web.extension);
48
+ *
49
+ *const cameraKit = await bootstrapCameraKit({ apiToken: "token from developer portal" }, extensions);
50
+ *const cameraKitSession = await cameraKit.createSession();
51
+ * ```
52
+ */
53
+ get extension(): import("@snap/camera-kit").PartialContainer<{
54
+ lensSources: import("@snap/camera-kit").LensSources;
55
+ }, {
56
+ lensSources: import("@snap/camera-kit").LensSources;
57
+ configuration: import("@snap/camera-kit").CameraKitConfiguration;
58
+ }>;
59
+ /**
60
+ * Initiate subscription for the events from Lens Studio.
61
+ *
62
+ * @param accessToken - After user will be logged in to the web page,
63
+ * using Snapchat account, you can get access token from Login Kit.
64
+ * @param cameraKitSession - Instance of CameraKitSesion object form @snap/camera-kit package.
65
+ * @param repository - Instance of LensRepository object from @snap/camera-kit package.
66
+ * @returns @SubscriptionInstance
67
+ */
68
+ subscribe(accessToken: string, cameraKitSession: CameraKitSession, repository: CameraKit["lensRepository"]): SubscriptionInstance;
69
+ }
70
+ export declare enum State {
71
+ /**
72
+ * The extension is listening for the events about pushed Lens from Lens Studio.
73
+ */
74
+ Subscribed = "Subscribed",
75
+ /**
76
+ * The extension is not listening for any events about pushed Lens.
77
+ */
78
+ Unsubscribed = "Unsubscribed"
79
+ }
80
+ export declare const version = "0.0.0-placeholder";
81
+ /**
82
+ * Generic error event
83
+ */
84
+ export type GenericErrorEvent = {
85
+ /**
86
+ * Type of the event.
87
+ */
88
+ name: "GenericError";
89
+ /**
90
+ * The reason of the error event.
91
+ */
92
+ cause: Error;
93
+ };
94
+ /**
95
+ * Error related to communication channel between the web page and Lens Studio.
96
+ */
97
+ export type CommunicationErrorEvent = {
98
+ /**
99
+ * Type of the event.
100
+ */
101
+ name: "CommunicationError";
102
+ /**
103
+ * The reason of the error event.
104
+ */
105
+ cause: Error;
106
+ /**
107
+ * gRPC connection code
108
+ */
109
+ grpcCode: number;
110
+ /**
111
+ * gRPC connection status
112
+ */
113
+ grpcStatus: Code;
114
+ };
115
+ /**
116
+ * This error will occur if the lens is excluded from push for any reason.
117
+ */
118
+ export type LensExcludedErrorEvent = {
119
+ /**
120
+ * Type of the event.
121
+ */
122
+ name: "LensExcludedError";
123
+ /**
124
+ * The reason of the error event.
125
+ */
126
+ cause: Error;
127
+ /**
128
+ * Lens id
129
+ */
130
+ lensId: number;
131
+ /**
132
+ * Contains the reason why the lens was excluded.
133
+ */
134
+ reason: ListenLensPushResponse_ExcludedLens_Code;
135
+ };
136
+ /**
137
+ * Object that represents active connection with Lens Studio.
138
+ */
139
+ export type SubscriptionInstance = {
140
+ /**
141
+ * Close current connection and unsubscribe from the events form Lens Studio.
142
+ */
143
+ unsubscribe(): void;
144
+ /**
145
+ * This method can be used to provide a new access token for an active connection
146
+ * in case the previous one has expired.
147
+ * @param accessToke Login Kit access token
148
+ */
149
+ updateAccessToken(accessToken: string): void;
150
+ };
151
+ export type ErrorEvent = TypedCustomEvent<"error", GenericErrorEvent | CommunicationErrorEvent | LensExcludedErrorEvent>;
152
+ export type LensReceivedEvent = TypedCustomEvent<"lensReceived", Lens>;
153
+ export type SubscriptionChangedEvent = TypedCustomEvent<"subscriptionChanged", State>;
154
+ export type Push2WebEvents = LensReceivedEvent | ErrorEvent | SubscriptionChangedEvent;
155
+ export type EventType = "error" | "lensReceived" | "subscriptionChanged";
@@ -0,0 +1,154 @@
1
+ import { cameraKitUserAgent, toPublicLens, TypedCustomEvent, TypedEventTarget, } from "@snap/camera-kit";
2
+ import { grpc } from "@improbable-eng/grpc-web";
3
+ import { map, catchError, of, switchMap, ReplaySubject } from "rxjs";
4
+ import { GrpcWebImpl, ListenLensPushRequest, listenLensPushResponse_ExcludedLens_CodeFromJSON, PushToDeviceClientImpl, } from "./generated-api-client/camera_kit/v3/push_to_device";
5
+ import { Envelope } from "./generated-api-client/camera_kit/v3/export";
6
+ import { codeFromJSON } from "./generated-api-client/core/snap_status_code";
7
+ import { Push2WebSDKExtension } from "./Push2WebSDKExtension";
8
+ export class Push2Web {
9
+ /**
10
+ * Use this property to subscribe for the different types of events that can occur during push 2 web execution.
11
+ *
12
+ * Subscribe to `error` event to be aware if something has happened during the lens push,
13
+ * with network communication or any other type of error,
14
+ * event object also contains detailed expalantion of the cause.
15
+ *
16
+ * Use `subscriptionChanged` event to be aware when subscription state is changed.
17
+ *
18
+ * Use `lensReceived` event to be aware when new lens is received from Lens Studio,
19
+ * also you can get the additional details about the pushed lens.
20
+ *
21
+ * @example
22
+ *```ts
23
+ *push2web.events.addEventListener('error', ({ detail }) => {
24
+ * if (detail.name === 'LensExcludedError') {
25
+ * console.log(`Lens is excluded from the push, by the following reason: ${detail.reason}.`)
26
+ * }
27
+ *})
28
+ *```
29
+ */
30
+ events = new TypedEventTarget();
31
+ push2WebExtension = new Push2WebSDKExtension();
32
+ pushedLenses;
33
+ accesToken = new ReplaySubject(1);
34
+ subscription;
35
+ /**
36
+ * Create new instance of Push2Web object,
37
+ * it can be used to start listening for the events,
38
+ * subscribe or unsubscribe for notifications from Lens Studio.
39
+ * Also provides the extension object for the @snap/camera-kit package.
40
+ */
41
+ constructor() {
42
+ this.pushedLenses = this.accesToken.pipe(switchMap((accessToken) => {
43
+ const metadata = new grpc.Metadata();
44
+ metadata.append("Authorization", `Bearer ${accessToken}`);
45
+ metadata.append("x-snap-client-user-agent", cameraKitUserAgent.userAgent);
46
+ const grpcWeb = new GrpcWebImpl("https://api-kit.snapchat.com", {
47
+ metadata,
48
+ });
49
+ const push2WebClient = new PushToDeviceClientImpl(grpcWeb);
50
+ return push2WebClient.ListenLensPush(ListenLensPushRequest.fromPartial({})).pipe(map(({ lenses, excludedLens }) => {
51
+ if (excludedLens) {
52
+ return new TypedCustomEvent("error", {
53
+ name: "LensExcludedError",
54
+ cause: new Error("Lens excluded"),
55
+ lensId: excludedLens.lensId,
56
+ reason: listenLensPushResponse_ExcludedLens_CodeFromJSON(excludedLens.code),
57
+ });
58
+ }
59
+ const envelope = Object.values(lenses)[0];
60
+ this.push2WebExtension.updateEnvelope(envelope);
61
+ const [lens] = Envelope.decode(envelope).lenses;
62
+ return new TypedCustomEvent("lensReceived", toPublicLens(lens));
63
+ }), catchError((error) => {
64
+ const grpcError = /Error ([\d]{1,3})/.exec(error.message);
65
+ if (grpcError) {
66
+ this.events.dispatchEvent(new TypedCustomEvent("subscriptionChanged", State.Unsubscribed));
67
+ const grpcCode = parseInt(grpcError[1]);
68
+ return of(new TypedCustomEvent("error", {
69
+ name: "CommunicationError",
70
+ cause: error,
71
+ grpcStatus: codeFromJSON(grpcCode),
72
+ grpcCode,
73
+ }));
74
+ }
75
+ return of(new TypedCustomEvent("error", { name: "GenericError", cause: error }));
76
+ }));
77
+ }));
78
+ }
79
+ /**
80
+ * The extension object must be passed to the Camera Kit object during its bootstrap process.
81
+ * This is a requirement for the proper functioning of push to web functionality.
82
+ *
83
+ * @example
84
+ * ```ts
85
+ *import { bootstrapCameraKit } from "@snap/camera-kit";
86
+ *
87
+ *const push2web = new Push2Web();
88
+ *const extensions = (container) => container.provides(push2Web.extension);
89
+ *
90
+ *const cameraKit = await bootstrapCameraKit({ apiToken: "token from developer portal" }, extensions);
91
+ *const cameraKitSession = await cameraKit.createSession();
92
+ * ```
93
+ */
94
+ get extension() {
95
+ return this.push2WebExtension.extension;
96
+ }
97
+ /**
98
+ * Initiate subscription for the events from Lens Studio.
99
+ *
100
+ * @param accessToken - After user will be logged in to the web page,
101
+ * using Snapchat account, you can get access token from Login Kit.
102
+ * @param cameraKitSession - Instance of CameraKitSesion object form @snap/camera-kit package.
103
+ * @param repository - Instance of LensRepository object from @snap/camera-kit package.
104
+ * @returns @SubscriptionInstance
105
+ */
106
+ subscribe(accessToken, cameraKitSession, repository) {
107
+ this.subscription?.unsubscribe();
108
+ this.accesToken.next(accessToken);
109
+ this.subscription = this.pushedLenses.subscribe({
110
+ next: async (event) => {
111
+ this.events.dispatchEvent(event);
112
+ if (event.type === "lensReceived") {
113
+ try {
114
+ const lens = await repository.loadLens(event.detail.id, this.push2WebExtension.groupId);
115
+ await cameraKitSession.removeLens();
116
+ await cameraKitSession.applyLens(lens);
117
+ }
118
+ catch (error) {
119
+ this.events.dispatchEvent(new TypedCustomEvent("error", {
120
+ name: "GenericError",
121
+ cause: error,
122
+ }));
123
+ }
124
+ }
125
+ this.push2WebExtension.reportEvent(event);
126
+ },
127
+ });
128
+ this.events.dispatchEvent(new TypedCustomEvent("subscriptionChanged", State.Subscribed));
129
+ return {
130
+ unsubscribe: async () => {
131
+ if (this.subscription) {
132
+ this.subscription.unsubscribe();
133
+ this.subscription = undefined;
134
+ this.events.dispatchEvent(new TypedCustomEvent("subscriptionChanged", State.Unsubscribed));
135
+ }
136
+ },
137
+ updateAccessToken: (accessToken) => {
138
+ this.accesToken.next(accessToken);
139
+ },
140
+ };
141
+ }
142
+ }
143
+ export var State;
144
+ (function (State) {
145
+ /**
146
+ * The extension is listening for the events about pushed Lens from Lens Studio.
147
+ */
148
+ State["Subscribed"] = "Subscribed";
149
+ /**
150
+ * The extension is not listening for any events about pushed Lens.
151
+ */
152
+ State["Unsubscribed"] = "Unsubscribed";
153
+ })(State || (State = {}));
154
+ export const version = "0.0.0-placeholder";
@@ -0,0 +1,17 @@
1
+ import { CameraKitConfiguration, LensSources } from "@snap/camera-kit";
2
+ import type { Push2WebEvents } from "./Push2Web";
3
+ export declare class Push2WebSDKExtension {
4
+ readonly extension: import("@snap/camera-kit").PartialContainer<{
5
+ lensSources: LensSources;
6
+ }, {
7
+ lensSources: LensSources;
8
+ configuration: CameraKitConfiguration;
9
+ }>;
10
+ groupId: string;
11
+ private lastPushedEnvelope;
12
+ private metricsReporter;
13
+ private metricRequestRateLimitMs;
14
+ constructor();
15
+ updateEnvelope(newEnvelope: ArrayBuffer): void;
16
+ reportEvent(events: Push2WebEvents): void;
17
+ }