Skip to content

Commit

Permalink
feat: Add call; fix: Sound unavailiable while using call
Browse files Browse the repository at this point in the history
  • Loading branch information
cwxia0s committed Nov 22, 2024
1 parent 7321006 commit 93807af
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 36 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ English | **[中文文档](README.zh.md)**
> There are bugs in Cloudflare Dashboard for now(2024-07-27), deploy and variables edit are not available, DONOT change anything before Cloudflare fix that. If you want to deploy, use wrangler. -->

> [!NOTE]
> On iOS 18, device token may change, the previous way to use multi-key or key alias may be unavailable, refer to [Tips](doc/tips.md) for more details.
> Device token may change, the previous way to use multi-key or key alias may be unavailable, refer to [Tips](doc/tips.md) for more details.
<!-- > [!CAUTION]
> For D1 Alpha Users: On August 1, 2024, D1 alpha databases will stop accepting live SQL queries. See [Migration Guide](https://developers.cloudflare.com/d1/platform/alpha-migration/) -->
Expand Down
2 changes: 1 addition & 1 deletion README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
> Cloudflare Dashboard 目前(2024-07-27)存在Bug, 部署和变量编辑不可用, 在Cloudflare修复该问题之前请勿进行任何操作, 如果需要部署请使用wrangler. -->

> [!NOTE]
> 在iOS 18 Beta 1上观察到device token变化的情况, 之前使用多Key或Key别名的方法可能会失效, 如有多Key使用需要参考[Tips](doc/tips.zh.md).
> Device token可能发生变化, 之前使用多Key或Key别名的方法可能会失效, 如有多Key使用需要参考[Tips](doc/tips.zh.md).
<!-- > [!CAUTION]
> 对于D1 Alpha用户: 在2024-08-01之后, D1 Alpha数据库将停止接受SQL查询,需要使用新的D1数据库,参考[迁移指南](https://developers.cloudflare.com/d1/platform/alpha-migration/) -->
Expand Down
2 changes: 1 addition & 1 deletion doc/tips.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Multi Device Key to One Device & Set Key Alias

> [!NOTE]
> In iOS 18, token may change after a period of time. If you need to use multiple keys or key alias, you can add the same server in your App for multiple times. If you need to use key alias, you can add the same server in your App, then manually set the key alias in database, and then use the reset key function in App to specify the key alias.
> Device token may change after a period of time. If you need to use multiple keys or key alias, you can add the same server in your App for multiple times. If you need to use key alias, you can add the same server in your App, then manually set the key alias in database, and then use the reset key function in App to specify the key alias.
In KV or D1 Database, Manually Set Records as follow:

Expand Down
2 changes: 1 addition & 1 deletion doc/tips.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## 一个设备多个Key或Key别名

> [!NOTE]
> 在iOS 18上观察到token变化的情况,此方法可能在使用一段时间后失效.如有多Key使用需求,直接在App中添加多次服务器即可.如果需要使用别名,先在App中添加一次服务器,在数据库中手动修改Key为别名,随后在App中使用重置Key功能指定Key别名.
> 设备token可能会随时间变化.如有多Key使用需求,直接在App中添加多次服务器即可.如果需要使用别名,先在App中添加一次服务器,在数据库中手动修改Key为别名,随后在App中使用重置Key功能指定Key别名.
在KV或D1数据库中, 按如下格式手动修改数据:

Expand Down
27 changes: 12 additions & 15 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ async function handleRequest(request, env, ctx) {
*/
class Handler {
constructor(env) {
this.version = "v2.1.2"
this.build = "2024-11-14 20:10:05"
this.version = "v2.1.3"
this.build = "2024-11-22 23:52:47"
this.arch = "js"
this.commit = "8bba6448095f56b0340b2df2af8eb7fbd13a5933"
this.commit = "73210060060f2d073e29ecec7b895a8ab470a6e7"

const db = new Database(env)

Expand Down Expand Up @@ -254,16 +254,17 @@ class Handler {
sound += '.caf'
}
const category = parameters.category || 'myNotificationCategory'
const group = parameters.group || 'Default'

const group = parameters.group || undefined

const call = parameters.call || undefined
const isArchive = parameters.isArchive || undefined
const icon = parameters.icon || undefined
const url = parameters.url || undefined
const ciphertext = parameters.ciphertext || undefined
const level = parameters.level || undefined
const url = parameters.url || undefined
const copy = parameters.copy || undefined
const badge = parameters.badge || 0
const badge = parameters.badge || undefined
const autoCopy = parameters.autoCopy || undefined
const ciphertext = parameters.ciphertext || undefined

// https://developer.apple.com/documentation/usernotifications/generating-a-remote-notification
const aps = {
Expand All @@ -280,12 +281,8 @@ class Handler {
'loc-key': undefined,
'loc-args': undefined,
},
'badge': 0,
'sound': {
'critical': 0,
'name': sound,
'volume': 1.0,
},
'badge': undefined,
'sound': sound,
'thread-id': group,
'category': category,
'content-available': undefined,
Expand All @@ -303,6 +300,7 @@ class Handler {
'attributes': undefined,
},
// ExtParams
'call': call,
'isarchive': isArchive,
'icon': icon,
'ciphertext': ciphertext,
Expand All @@ -311,7 +309,6 @@ class Handler {
'copy': copy,
'badge': badge,
'autocopy': autoCopy,
'group': group,
}

const apns = new APNs(db)
Expand Down
31 changes: 14 additions & 17 deletions main_kv.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ async function handleRequest(request, env, ctx) {
*/
class Handler {
constructor(env) {
this.version = "v2.1.2"
this.build = "2024-11-14 20:10:05"
this.version = "v2.1.3"
this.build = "2024-11-22 23:52:47"
this.arch = "js"
this.commit = "8bba6448095f56b0340b2df2af8eb7fbd13a5933"
this.commit = "73210060060f2d073e29ecec7b895a8ab470a6e7"

const db = new Database(env)

Expand Down Expand Up @@ -254,16 +254,17 @@ class Handler {
sound += '.caf'
}
const category = parameters.category || 'myNotificationCategory'
const group = parameters.group || 'Default'

const group = parameters.group || undefined

const call = parameters.call || undefined
const isArchive = parameters.isArchive || undefined
const icon = parameters.icon || undefined
const url = parameters.url || undefined
const ciphertext = parameters.ciphertext || undefined
const level = parameters.level || undefined
const url = parameters.url || undefined
const copy = parameters.copy || undefined
const badge = parameters.badge || 0
const badge = parameters.badge || undefined
const autoCopy = parameters.autoCopy || undefined
const ciphertext = parameters.ciphertext || undefined

// https://developer.apple.com/documentation/usernotifications/generating-a-remote-notification
const aps = {
Expand All @@ -280,12 +281,8 @@ class Handler {
'loc-key': undefined,
'loc-args': undefined,
},
'badge': 0,
'sound': {
'critical': 0,
'name': sound,
'volume': 1.0,
},
'badge': undefined,
'sound': sound,
'thread-id': group,
'category': category,
'content-available': undefined,
Expand All @@ -303,6 +300,7 @@ class Handler {
'attributes': undefined,
},
// ExtParams
'call': call,
'isarchive': isArchive,
'icon': icon,
'ciphertext': ciphertext,
Expand All @@ -311,7 +309,6 @@ class Handler {
'copy': copy,
'badge': badge,
'autocopy': autoCopy,
'group': group,
}

const apns = new APNs(db)
Expand Down Expand Up @@ -440,7 +437,7 @@ class Database {
}

this.saveDeviceTokenByKey = async (key, token) => {
const device_token = (key || '').replace(/[^a-z0-9]/g, '') || "_PLACE_HOLDER_"
const device_token = (token || '').replace(/[^a-z0-9]/g, '') || "_PLACE_HOLDER_"
const deviceToken = await kvStorage.put(key, device_token)
return await deviceToken
}
Expand All @@ -451,7 +448,7 @@ class Database {
}

this.authorizationToken = async () => {
await kvStorage.get('_authToken_')
return await kvStorage.get('_authToken_')
}
}
}
Expand Down

0 comments on commit 93807af

Please sign in to comment.