diff --git a/demo.html b/demo.html
new file mode 100644
index 0000000..867b790
--- /dev/null
+++ b/demo.html
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+ DEMO
+
+
+
+
+
diff --git a/package.json b/package.json
index c5ee7c1..55d085d 100644
--- a/package.json
+++ b/package.json
@@ -22,7 +22,7 @@
"dependencies": {
"express": "^4.18.2",
"express-ws": "^5.0.2",
- "node-turn": "^0.0.6",
- "uuid": "^9.0.1"
+ "idb": "^7.1.1",
+ "node-turn": "^0.0.6"
}
}
diff --git a/src/main.js b/src/main.js
index f96bf1c..3416d4e 100644
--- a/src/main.js
+++ b/src/main.js
@@ -21,8 +21,8 @@ function appendBuffer(buffer1, buffer2) {
// 读取本地音乐列表并标识为缓存状态(本地缓存)
const database = new IndexedDB('musicDatabase', 1)
await database.store('musicObjectStore') // 音乐(为什么会用这么丑的格式呢)
-await database.store('imageObjectStore') // 图像(为什么会用这么丑的格式呢)
-await database.store('chatsObjectStore') // 聊天室
+//await database.store('imageObjectStore') // 图像(为什么会用这么丑的格式呢)
+//await database.store('chatsObjectStore') // 聊天室
// 读取本地音乐列表并标识为缓存状态(本地缓存)
const list = (await database.getAll('musicObjectStore')).map(item => {
diff --git a/src/store.js b/src/store.js
index 32ca703..4b7d06d 100644
--- a/src/store.js
+++ b/src/store.js
@@ -1,4 +1,12 @@
-import { v4 } from 'uuid'
+// 使用封装为支持异步的 IndexedDB
+import { openDB, deleteDB, wrap, unwrap } from 'idb'
+const storenames = ['music', 'chat', 'user']
+const database = await openDB('database', 1, {
+ upgrade(db) {
+ storenames.forEach(name => db.createObjectStore(name, { keyPath: 'id' }))
+ console.log('store created:', storenames)
+ }
+})
export class Store {
constructor(data) {
@@ -7,7 +15,7 @@ export class Store {
}
create(data) {
- const id = v4()
+ const id = window.crypto.randomUUID()
return { id, ...data }
}
@@ -16,7 +24,7 @@ export class Store {
query() {}
}
-export const music = new Store({
+export const musicStore = new Store({
name: '音乐(资源类型)',
info: '音乐(类型说明)',
存储时间: 1000 * 60 * 60 * 24 * 7, // 7天不使用的资源将被删除
@@ -30,7 +38,7 @@ export const music = new Store({
}]
})
-export const chat = new Store({
+export const chatStore = new Store({
name: '聊天(资源类型)',
info: '聊天(类型说明)',
存储时间: 1000 * 60 * 60 * 24 * 7, // 7天不使用的资源将被删除