@xhub-short/sdk 0.1.0-beta.4 → 0.1.0-beta.5
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/README.md +69 -0
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -597,6 +597,75 @@ import { VideoSlotOverlay, VideoSlotPoster } from '@xhub-short/ui';
|
|
|
597
597
|
|
|
598
598
|
---
|
|
599
599
|
|
|
600
|
+
## 👤 Guest Mode (Chế độ khách)
|
|
601
|
+
|
|
602
|
+
SDK hỗ trợ chế độ khách cho phép người dùng chưa đăng nhập xem video và bình luận (read-only). Các tương tác (Like, Comment, Follow) sẽ bị chặn và trigger callback để Host App xử lý (ví dụ: hiện modal đăng nhập).
|
|
603
|
+
|
|
604
|
+
### Cấu hình
|
|
605
|
+
|
|
606
|
+
```tsx
|
|
607
|
+
<ShortVideoRoot
|
|
608
|
+
config={{
|
|
609
|
+
// ...
|
|
610
|
+
guest: {
|
|
611
|
+
/**
|
|
612
|
+
* 'auto': Tự động detect dựa trên auth token (default)
|
|
613
|
+
* true: Force guest mode
|
|
614
|
+
* false: Disable guest mode
|
|
615
|
+
*/
|
|
616
|
+
mode: 'auto',
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* Callback khi guest thực hiện hành động cần auth (Like, Comment, Follow...)
|
|
620
|
+
*/
|
|
621
|
+
onAction: (action, context) => {
|
|
622
|
+
console.log('Guest Action:', action, context);
|
|
623
|
+
// VD: showLoginModal();
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
}}
|
|
627
|
+
>
|
|
628
|
+
<VideoFeed />
|
|
629
|
+
</ShortVideoRoot>
|
|
630
|
+
```
|
|
631
|
+
|
|
632
|
+
### Các hành động được chặn
|
|
633
|
+
- **Like / Bookmark**: Trigger `onAction`
|
|
634
|
+
- **Follow**: Trigger `onAction`
|
|
635
|
+
- **Comment Input**: Hiển thị nút "Login to comment". Khi click triggers `onAction` (`action='comment'`).
|
|
636
|
+
|
|
637
|
+
---
|
|
638
|
+
|
|
639
|
+
## ⚡ Prefetch Data (Tải trước dữ liệu)
|
|
640
|
+
|
|
641
|
+
Cho phép Host App tải trước dữ liệu Feed (Reels) để trải nghiệm hiển thị tức thì (instant loading).
|
|
642
|
+
|
|
643
|
+
### Cách sử dụng
|
|
644
|
+
|
|
645
|
+
Gọi hàm `prefetchFeed` trước khi mount SDK components (ví dụ: khi hover vào menu Reels hoặc trong route loader).
|
|
646
|
+
|
|
647
|
+
```tsx
|
|
648
|
+
import { prefetchFeed } from '@xhub-short/sdk';
|
|
649
|
+
|
|
650
|
+
// 1. Prefetch data (lưu vào bộ nhớ tạm)
|
|
651
|
+
// Có thể gọi ở bất kỳ đâu trong Host App
|
|
652
|
+
await prefetchFeed(sdkConfig, { ttl: 5 * 60 * 1000 });
|
|
653
|
+
|
|
654
|
+
// ... Sau đó ...
|
|
655
|
+
|
|
656
|
+
// 2. Khi User vào trang Reels, SDK sẽ tự động dùng data đã fetch
|
|
657
|
+
<ShortVideoRoot config={sdkConfig}>
|
|
658
|
+
<VideoFeed />
|
|
659
|
+
</ShortVideoRoot>
|
|
660
|
+
```
|
|
661
|
+
|
|
662
|
+
### Đặc điểm
|
|
663
|
+
- **In-Memory Cache**: Dữ liệu chỉ lưu tạm trong RAM, mất khi refresh trang (đảm bảo fresh data).
|
|
664
|
+
- **Auto-Consume**: `ShortVideoRoot` tự động tiêu thụ cache và xóa sau khi dùng.
|
|
665
|
+
- **Performance**: Giúp giảm thời gian chờ đợi (LCP) xuống gần bằng 0 khi user chuyển trang.
|
|
666
|
+
|
|
667
|
+
---
|
|
668
|
+
|
|
600
669
|
## 🔗 Liên kết với các Packages
|
|
601
670
|
|
|
602
671
|
| Package | Quan hệ với SDK |
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xhub-short/sdk",
|
|
3
3
|
"sideEffects": false,
|
|
4
|
-
"version": "0.1.0-beta.
|
|
4
|
+
"version": "0.1.0-beta.5",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -20,13 +20,13 @@
|
|
|
20
20
|
"dist"
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@xhub-short/
|
|
24
|
-
"@xhub-short/
|
|
25
|
-
"@xhub-short/core": "0.1.0-beta.
|
|
26
|
-
"@xhub-short/ui": "0.1.0-beta.
|
|
23
|
+
"@xhub-short/contracts": "0.1.0-beta.5",
|
|
24
|
+
"@xhub-short/adapters": "0.1.0-beta.5",
|
|
25
|
+
"@xhub-short/core": "0.1.0-beta.5",
|
|
26
|
+
"@xhub-short/ui": "0.1.0-beta.5"
|
|
27
27
|
},
|
|
28
28
|
"optionalDependencies": {
|
|
29
|
-
"@xhub-short/bridge": "0.0.1-beta.
|
|
29
|
+
"@xhub-short/bridge": "0.0.1-beta.5"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"react": "^19.0.0",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"tsup": "^8.3.0",
|
|
43
43
|
"typescript": "^5.7.0",
|
|
44
44
|
"vitest": "^2.1.0",
|
|
45
|
-
"@xhub-short/
|
|
46
|
-
"@xhub-short/
|
|
45
|
+
"@xhub-short/vitest-config": "0.0.1-beta.4",
|
|
46
|
+
"@xhub-short/tsconfig": "0.0.0"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"build": "tsup",
|