@streamlayer/sdk-web-core 0.20.0 → 0.21.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/lib/auth/bypass/index.js +6 -3
- package/lib/deepLink/index.d.ts +8 -8
- package/lib/deepLink/index.js +64 -44
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/videoPlayer/index.d.ts +19 -0
- package/lib/videoPlayer/index.js +22 -0
- package/package.json +6 -5
package/lib/auth/bypass/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { AbstractAuthenticationProvider } from '@streamlayer/sdk-web-interfaces';
|
|
2
2
|
import { queries } from '@streamlayer/sdk-web-api';
|
|
3
|
+
import { createLogger } from '@streamlayer/sdk-web-logger';
|
|
3
4
|
import { DEEP_LINK_USER_ID } from '../../deepLink';
|
|
4
5
|
import { UserStorage } from '../../storage';
|
|
6
|
+
const logger = createLogger('bypass');
|
|
5
7
|
/**
|
|
6
8
|
* An authorization service manages user access by providing login, logout,
|
|
7
9
|
* authentication checks, and the ability to revoke access.
|
|
@@ -33,8 +35,9 @@ export class BypassAuth extends AbstractAuthenticationProvider {
|
|
|
33
35
|
*/
|
|
34
36
|
login = async (schema, userKey) => {
|
|
35
37
|
this.$coreStore.getValues().userKey.setValue(userKey);
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
+
const { used, data } = this.deepLink.getDeepLinkData();
|
|
39
|
+
const inviterKey = !used ? data?.[DEEP_LINK_USER_ID] : '';
|
|
40
|
+
logger.debug('inviterKey', inviterKey);
|
|
38
41
|
const user = await this.bypassLogin({
|
|
39
42
|
schema,
|
|
40
43
|
userKey,
|
|
@@ -46,7 +49,7 @@ export class BypassAuth extends AbstractAuthenticationProvider {
|
|
|
46
49
|
if (!token || !userId) {
|
|
47
50
|
throw new Error('internal: token missing');
|
|
48
51
|
}
|
|
49
|
-
|
|
52
|
+
logger.debug('user', user);
|
|
50
53
|
if (user.meta?.inviterKey) {
|
|
51
54
|
this.deepLink.deepLinkUsed(user.meta.inviterKey);
|
|
52
55
|
}
|
package/lib/deepLink/index.d.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { StreamLayerContext } from '@streamlayer/sdk-web-interfaces';
|
|
2
2
|
import { MapStore } from '@streamlayer/sdk-web-interfaces';
|
|
3
3
|
type DeepLinkContextData = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
sessionId?: string;
|
|
4
|
+
handled?: boolean;
|
|
5
|
+
parsed?: boolean;
|
|
6
|
+
used?: boolean;
|
|
8
7
|
data?: DeepLinkUrlParams;
|
|
9
8
|
};
|
|
10
9
|
export type DeepLinkCallback = (deepLinkData: DeepLinkContextData['data']) => void;
|
|
11
10
|
export interface DeepLinkContext {
|
|
12
11
|
$store: DeepLinkContextStore;
|
|
13
|
-
getDeepLinkData: () => DeepLinkContextData
|
|
12
|
+
getDeepLinkData: () => Pick<DeepLinkContextData, 'data' | 'used'>;
|
|
14
13
|
deepLinkUsed: (inviterId: string) => void;
|
|
15
14
|
onDeepLinkHandlers: Set<DeepLinkCallback>;
|
|
16
15
|
}
|
|
@@ -20,9 +19,10 @@ declare module '@streamlayer/sdk-web-interfaces' {
|
|
|
20
19
|
deepLink: DeepLinkContext;
|
|
21
20
|
}
|
|
22
21
|
interface StreamLayerSDK {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
addDeepLinkHandler: (cb: DeepLinkCallback) => void;
|
|
23
|
+
removeDeepLinkHandler: (cb: DeepLinkCallback) => void;
|
|
24
|
+
getInviter: () => string | undefined;
|
|
25
|
+
inviteDisplayed: () => void;
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
export declare const DEEP_LINK_PREFIX = "sldl";
|
package/lib/deepLink/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createMapStore, MapStore } from '@streamlayer/sdk-web-interfaces';
|
|
2
2
|
import { Storage } from '@streamlayer/sdk-web-storage';
|
|
3
|
+
import { createLogger } from '@streamlayer/sdk-web-logger';
|
|
3
4
|
class DeepLinkContextStorage extends Storage {
|
|
4
5
|
get = this.read;
|
|
5
6
|
set = this.write;
|
|
@@ -15,35 +16,62 @@ export const DEEP_LINK_EXTERNAL_EVENT_ID = 'sldl_e_eid';
|
|
|
15
16
|
const ALLOWED_PARAMS = new Set([DEEP_LINK_USER_ID, DEEP_LINK_EVENT_ID, DEEP_LINK_EXTERNAL_EVENT_ID]);
|
|
16
17
|
const pickOnlyAllowedParams = (params) => {
|
|
17
18
|
const result = {};
|
|
19
|
+
const remain = {};
|
|
18
20
|
for (const [key, value] of params) {
|
|
19
21
|
if (ALLOWED_PARAMS.has(key)) {
|
|
20
22
|
result[key] = value;
|
|
21
23
|
}
|
|
24
|
+
else {
|
|
25
|
+
remain[key] = value;
|
|
26
|
+
}
|
|
22
27
|
}
|
|
23
|
-
return result;
|
|
28
|
+
return { result, remain };
|
|
24
29
|
};
|
|
25
30
|
const parseDeepLinkData = ({ hash, search }) => {
|
|
26
31
|
if (hash && hash.includes(DEEP_LINK_PREFIX)) {
|
|
27
32
|
const params = new URLSearchParams(hash.substr(1));
|
|
28
|
-
return pickOnlyAllowedParams(params);
|
|
33
|
+
return { hash: pickOnlyAllowedParams(params) };
|
|
29
34
|
}
|
|
30
35
|
if (search && search.includes(DEEP_LINK_PREFIX)) {
|
|
31
36
|
const params = new URLSearchParams(search);
|
|
32
|
-
return pickOnlyAllowedParams(params);
|
|
37
|
+
return { search: pickOnlyAllowedParams(params) };
|
|
33
38
|
}
|
|
34
39
|
return null;
|
|
35
40
|
};
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
const logger = createLogger('deep_link');
|
|
42
|
+
const pickDeepLinkData = ($deepLinkContext, deepLinkHandled) => {
|
|
43
|
+
const { hash, search } = window.location;
|
|
44
|
+
logger.debug({ hash, search }, 'get deep link data from');
|
|
45
|
+
if (hash || search) {
|
|
46
|
+
const parsedData = parseDeepLinkData({ hash, search });
|
|
47
|
+
logger.debug(parsedData, 'parse deep link result');
|
|
48
|
+
if (parsedData) {
|
|
49
|
+
const { hash, search } = parsedData;
|
|
50
|
+
const { result, remain } = hash || search;
|
|
51
|
+
if (Object.keys(result).length !== 0) {
|
|
52
|
+
$deepLinkContext.setValue('data', result);
|
|
53
|
+
const remainExist = Object.keys(remain).length !== 0;
|
|
54
|
+
if (hash) {
|
|
55
|
+
let updatedHash = '';
|
|
56
|
+
if (remainExist) {
|
|
57
|
+
updatedHash = `#${new URLSearchParams(remain).toString()}`;
|
|
58
|
+
logger.debug({ updatedHash }, 'update hash');
|
|
59
|
+
}
|
|
60
|
+
window.history.replaceState(null, '', window.location.pathname + window.location.search + updatedHash);
|
|
61
|
+
}
|
|
62
|
+
if (search) {
|
|
63
|
+
let updatedSearch = '';
|
|
64
|
+
if (remainExist) {
|
|
65
|
+
updatedSearch = `?${new URLSearchParams(remain).toString()}`;
|
|
66
|
+
logger.debug({ updatedSearch }, 'update search');
|
|
67
|
+
}
|
|
68
|
+
window.history.replaceState(null, '', window.location.pathname + updatedSearch + window.location.hash);
|
|
69
|
+
}
|
|
70
|
+
deepLinkHandled(result);
|
|
71
|
+
}
|
|
44
72
|
}
|
|
45
|
-
return;
|
|
46
73
|
}
|
|
74
|
+
$deepLinkContext.setValue('parsed', true);
|
|
47
75
|
return;
|
|
48
76
|
};
|
|
49
77
|
/**
|
|
@@ -53,43 +81,50 @@ const pickDeepLinkData = ($deepLinkContext) => {
|
|
|
53
81
|
export const deepLink = (instance, opts, done) => {
|
|
54
82
|
const storage = new DeepLinkContextStorage();
|
|
55
83
|
const initStoreStr = storage.get('sl-deep-link-store');
|
|
56
|
-
let initStore = {
|
|
84
|
+
let initStore = {};
|
|
57
85
|
if (initStoreStr) {
|
|
58
86
|
try {
|
|
59
87
|
initStore = JSON.parse(initStoreStr);
|
|
60
88
|
}
|
|
61
89
|
catch (e) {
|
|
62
|
-
|
|
90
|
+
logger.debug(e);
|
|
63
91
|
}
|
|
64
92
|
}
|
|
65
93
|
instance.deepLink = {
|
|
66
94
|
$store: new MapStore(createMapStore(initStore), 'deep-link-context'),
|
|
67
95
|
getDeepLinkData: () => {
|
|
68
|
-
const { data,
|
|
69
|
-
return
|
|
96
|
+
const { data, used } = instance.deepLink.$store.getValues();
|
|
97
|
+
return { data, used };
|
|
70
98
|
},
|
|
71
99
|
// we are logged in with inviter id
|
|
72
100
|
deepLinkUsed: (inviterId) => {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
storage.del('sl-location');
|
|
101
|
+
logger.debug(`logged in with inviterId: ${inviterId}`);
|
|
102
|
+
instance.deepLink.$store.setValue('used', true);
|
|
76
103
|
},
|
|
77
104
|
onDeepLinkHandlers: new Set(),
|
|
78
105
|
};
|
|
79
|
-
instance.
|
|
80
|
-
|
|
81
|
-
return
|
|
106
|
+
instance.sdk.getInviter = () => {
|
|
107
|
+
const { data, used } = instance.deepLink.getDeepLinkData();
|
|
108
|
+
return used ? data?.[DEEP_LINK_USER_ID] : undefined;
|
|
82
109
|
};
|
|
83
|
-
instance.sdk.
|
|
110
|
+
instance.sdk.inviteDisplayed = () => {
|
|
111
|
+
instance.deepLink.$store.getStore().set({});
|
|
112
|
+
instance.deepLink.$store.getStore().off();
|
|
113
|
+
storage.del('sl-deep-link-store');
|
|
114
|
+
};
|
|
115
|
+
instance.deepLink.$store.subscribe((value) => storage.set('sl-deep-link-store', JSON.stringify(value)));
|
|
116
|
+
instance.sdk.addDeepLinkHandler = (cb) => {
|
|
84
117
|
instance.deepLink.onDeepLinkHandlers.add(cb);
|
|
85
118
|
};
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
119
|
+
instance.sdk.removeDeepLinkHandler = (cb) => {
|
|
120
|
+
instance.deepLink.onDeepLinkHandlers.delete(cb);
|
|
121
|
+
};
|
|
122
|
+
// called after sdk parsed deep link data from location
|
|
123
|
+
const deepLinkHandled = (data) => {
|
|
124
|
+
instance.deepLink.$store.setValue('handled', true);
|
|
91
125
|
for (const handler of instance.deepLink.onDeepLinkHandlers) {
|
|
92
126
|
try {
|
|
127
|
+
logger.debug('called handler');
|
|
93
128
|
handler(data);
|
|
94
129
|
}
|
|
95
130
|
catch (err) {
|
|
@@ -97,21 +132,6 @@ export const deepLink = (instance, opts, done) => {
|
|
|
97
132
|
}
|
|
98
133
|
}
|
|
99
134
|
};
|
|
100
|
-
|
|
101
|
-
if (!sessionId) {
|
|
102
|
-
const { hash, search } = window.location;
|
|
103
|
-
sessionId = Date.now().toString();
|
|
104
|
-
storage.set('sl-session-id', sessionId);
|
|
105
|
-
storage.set('sl-location', JSON.stringify({ hash, search }));
|
|
106
|
-
instance.deepLink.$store.getStore().set({ sessionId, hash, search, processed: false });
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
const initialLocation = storage.get('sl-location');
|
|
110
|
-
if (initialLocation) {
|
|
111
|
-
const parsed = JSON.parse(initialLocation);
|
|
112
|
-
instance.deepLink.$store.getStore().set({ sessionId, hash: parsed.hash, search: parsed.search, processed: false });
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
pickDeepLinkData(instance.deepLink.$store);
|
|
135
|
+
pickDeepLinkData(instance.deepLink.$store, deepLinkHandled);
|
|
116
136
|
done();
|
|
117
137
|
};
|
package/lib/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { StreamLayerContext } from '@streamlayer/sdk-web-interfaces';
|
|
|
2
2
|
export { bypass, storage } from './auth';
|
|
3
3
|
export { store } from './store';
|
|
4
4
|
export { deepLink, type DeepLinkUrlParams, type DeepLinkCallback, DEEP_LINK_PREFIX, DEEP_LINK_USER_ID, DEEP_LINK_EVENT_ID, DEEP_LINK_EXTERNAL_EVENT_ID, } from './deepLink';
|
|
5
|
+
export { videoPlayer, type VideoPlayerCallback } from './videoPlayer';
|
|
5
6
|
import './store';
|
|
6
7
|
import './auth';
|
|
7
8
|
declare module '@streamlayer/sdk-web-interfaces' {
|
package/lib/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import { CoreStatus } from './store/store';
|
|
|
2
2
|
export { bypass, storage } from './auth';
|
|
3
3
|
export { store } from './store';
|
|
4
4
|
export { deepLink, DEEP_LINK_PREFIX, DEEP_LINK_USER_ID, DEEP_LINK_EVENT_ID, DEEP_LINK_EXTERNAL_EVENT_ID, } from './deepLink';
|
|
5
|
+
export { videoPlayer } from './videoPlayer';
|
|
5
6
|
import './store';
|
|
6
7
|
import './auth';
|
|
7
8
|
/**
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { StreamLayerContext } from '@streamlayer/sdk-web-interfaces';
|
|
2
|
+
export type VideoPlayerData = {
|
|
3
|
+
muted: boolean;
|
|
4
|
+
};
|
|
5
|
+
export type VideoPlayerCallback = (videoPlayerData: VideoPlayerData) => void;
|
|
6
|
+
export interface VideoPlayerContext {
|
|
7
|
+
controllers: Set<VideoPlayerCallback>;
|
|
8
|
+
}
|
|
9
|
+
declare module '@streamlayer/sdk-web-interfaces' {
|
|
10
|
+
interface StreamLayerContext {
|
|
11
|
+
videoPlayer: VideoPlayerContext;
|
|
12
|
+
}
|
|
13
|
+
interface StreamLayerSDK {
|
|
14
|
+
addVideoPlayerController: (cb: VideoPlayerCallback) => void;
|
|
15
|
+
removeVideoPlayerController: (cb: VideoPlayerCallback) => void;
|
|
16
|
+
controlVideoPlayer: VideoPlayerCallback;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export declare const videoPlayer: (instance: StreamLayerContext, opts: unknown, done: () => void) => void;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export const videoPlayer = (instance, opts, done) => {
|
|
2
|
+
instance.videoPlayer = {
|
|
3
|
+
controllers: new Set(),
|
|
4
|
+
};
|
|
5
|
+
instance.sdk.addVideoPlayerController = (cb) => {
|
|
6
|
+
instance.videoPlayer.controllers.add(cb);
|
|
7
|
+
};
|
|
8
|
+
instance.sdk.removeVideoPlayerController = (cb) => {
|
|
9
|
+
instance.videoPlayer.controllers.delete(cb);
|
|
10
|
+
};
|
|
11
|
+
instance.sdk.controlVideoPlayer = (props) => {
|
|
12
|
+
for (const controller of instance.videoPlayer.controllers) {
|
|
13
|
+
try {
|
|
14
|
+
controller(props);
|
|
15
|
+
}
|
|
16
|
+
catch (err) {
|
|
17
|
+
console.error(err);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
done();
|
|
22
|
+
};
|
package/package.json
CHANGED
|
@@ -7,10 +7,11 @@
|
|
|
7
7
|
"@nanostores/query": "^0.2.8",
|
|
8
8
|
"@streamlayer/sl-eslib": "^5.67.0",
|
|
9
9
|
"nanostores": "^0.9.5",
|
|
10
|
-
"@streamlayer/sdk-web-api": "^0.
|
|
11
|
-
"@streamlayer/sdk-web-interfaces": "^0.20.
|
|
12
|
-
"@streamlayer/sdk-web-storage": "^0.4.
|
|
13
|
-
"@streamlayer/sdk-web-
|
|
10
|
+
"@streamlayer/sdk-web-api": "^0.22.0",
|
|
11
|
+
"@streamlayer/sdk-web-interfaces": "^0.20.5",
|
|
12
|
+
"@streamlayer/sdk-web-storage": "^0.4.3",
|
|
13
|
+
"@streamlayer/sdk-web-logger": "^0.5.16",
|
|
14
|
+
"@streamlayer/sdk-web-types": "^0.22.3"
|
|
14
15
|
},
|
|
15
16
|
"exports": {
|
|
16
17
|
".": {
|
|
@@ -39,7 +40,7 @@
|
|
|
39
40
|
"default": "./lib/auth/index.js"
|
|
40
41
|
}
|
|
41
42
|
},
|
|
42
|
-
"version": "0.
|
|
43
|
+
"version": "0.21.0",
|
|
43
44
|
"type": "module",
|
|
44
45
|
"main": "./lib/index.js",
|
|
45
46
|
"module": "./lib/index.js",
|