@kispi/chat 0.7.0 → 0.7.2
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.en.md +33 -4
- package/README.md +26 -4
- package/dist/index.cjs +31 -4
- package/dist/index.d.cts +24 -3
- package/dist/index.d.ts +24 -3
- package/dist/index.js +31 -4
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -88,7 +88,7 @@ off()
|
|
|
88
88
|
| `reactionsOf(messageId, {emoji?, cursor?, limit?})` | Who reacted. **Each row is a (user, emoji) pair**, so one person can appear on several rows. `limit` defaults to 50, max 100; the last page's `cursor` is an empty string |
|
|
89
89
|
| `markRead(seq, {threadId?})` | Read cursor |
|
|
90
90
|
| `reads({userId?, cursor?, limit?})` | Read cursors, paged. `{reads: [{userId?, seq, threadId?, withdrawn?}], cursor}`. **`userId` narrows to one person** -- `reads({userId: chat.user.id})` recovers your own per-thread cursors. Stop when `cursor` is `''` |
|
|
91
|
-
| `typing({threadId?})` | Typing indicator. Does not throw. Pass `threadId` while writing a thread reply |
|
|
91
|
+
| `typing({threadId?})` | Typing indicator. Does not throw. **Call it on every input event** — the SDK sends at most once per second per room. Pass `threadId` while writing a thread reply |
|
|
92
92
|
| `join()` / `leave()` | Membership |
|
|
93
93
|
| `presenceList()` | Who is in this room right now |
|
|
94
94
|
|
|
@@ -96,10 +96,10 @@ Event names are **exactly the wire names**, and the payloads are in the type dec
|
|
|
96
96
|
|
|
97
97
|
| Event | Payload |
|
|
98
98
|
|---|---|
|
|
99
|
-
| `message.created` / `message.updated` | `Message`. On `created`, `thread` is absent
|
|
99
|
+
| `message.created` / `message.updated` | `Message`. On `created`, `thread` is absent, `reactions` is empty, and **the SDK fills `myReactions` with `[]`** (the wire carries none) |
|
|
100
100
|
| `message.deleted` | `{id, seq}`. `seq` is the one the message got **when it was published** |
|
|
101
101
|
| `reaction.added` / `reaction.removed` | `{messageId, emoji, count, userId?}`. The SDK has already updated that row's `reactions` count in `messages` (and `myReactions` if it was yours). **Rows outside the list**, such as ones read with `history()`, are the consumer's to update |
|
|
102
|
-
| `thread.updated` | `{rootId, count, lastSeq?, lastAt?}` |
|
|
102
|
+
| `thread.updated` | `{rootId, count, lastSeq?, lastAt?}`. The SDK has already updated **the root row's `thread`** (`count`, `lastSeq`, `lastAt`) in `messages`. A root outside the list is the consumer's to update |
|
|
103
103
|
| `presence` | `{count, joined?, left?, users?, capped?}`. `joined`/`left` are incremental, `users` replaces |
|
|
104
104
|
| `typing` | `{userId, threadId?}` -- `threadId` is the thread **root** id, absent for the main timeline |
|
|
105
105
|
| `read` | `{userId, seq, threadId?}` |
|
|
@@ -139,17 +139,40 @@ room.on('messages', m => (messages.value = m))
|
|
|
139
139
|
that nobody fills.
|
|
140
140
|
- **Attach the past to the same list with `loadOlder()`.** `history()` is a direct read that
|
|
141
141
|
doesn't touch the list, so merging and deduplicating fall to you.
|
|
142
|
+
- **Draw reaction chips from `reactions` and `myReactions` together.** `react()` moves
|
|
143
|
+
`myReactions` first and waits for `reaction.added` for the count, so an emoji you are the first
|
|
144
|
+
to add sits briefly in `myReactions` only. Draw that chip as **the highlighted emoji alone** (no
|
|
145
|
+
count) rather than inventing a `1` — someone else may have pressed it in between.
|
|
146
|
+
- **Each message has a cap on distinct emoji** (`hello.limits.maxDistinctEmojiPerMessage`, 20 by
|
|
147
|
+
default). A new emoji past it is refused with `invalid` and the SDK rolls `myReactions` back.
|
|
148
|
+
Pressing an emoji already on the message is never capped. To disable a picker, check that
|
|
149
|
+
`reactions.length` has reached the cap and the emoji is not among them.
|
|
150
|
+
- **A thread panel merges two sources.** `messages` holds replies only for the range the SDK has
|
|
151
|
+
read (it is the whole room's stream, so an old thread's replies are not in it). Read past replies
|
|
152
|
+
with `history({view: {thread: rootId}})`, pick new ones from `messages` by
|
|
153
|
+
`threadId === rootId`, and **merge by id.** Rows read with `history()` are outside the list, so
|
|
154
|
+
**you apply** `reaction.added`/`removed` (the count, and `myReactions` when `userId` is yours),
|
|
155
|
+
`message.updated` and `message.deleted` to them yourself — miss it and only the older replies'
|
|
156
|
+
reactions look frozen. Read again on `reset`.
|
|
142
157
|
- **`typing` is also delivered to the sender.** If you render "X is typing", skip your own `userId`.
|
|
143
158
|
- **`typing` carries no name.** Look the name up in `room.presence.users` — whoever is
|
|
144
159
|
watching the room is there. Collecting names from message senders misses anyone who has not
|
|
145
160
|
spoken yet. If `users` is absent (a room over 100), fetch it once with `presenceList()`, and fall
|
|
146
161
|
back to a placeholder if the name is still missing.
|
|
162
|
+
- **`typing` arrives at most once per person per room every three seconds.** There is no
|
|
163
|
+
"stopped" event, so keep the indicator for **five seconds or more** after the last one — even
|
|
164
|
+
someone typing steadily can be broadcast more than four seconds apart, and anything shorter
|
|
165
|
+
blinks between events.
|
|
166
|
+
- **Each room announces only a few typists at a time** (three today). Every broadcast goes out
|
|
167
|
+
once per person in the room, and a screen draws "A, B and C are typing" at most anyway. In a
|
|
168
|
+
busy room some people typing are never announced — don't write code that depends on the number
|
|
169
|
+
(the engine may change it).
|
|
147
170
|
|
|
148
171
|
```ts
|
|
149
172
|
room.on('typing', ({ userId }) => {
|
|
150
173
|
if (userId === chat.user?.id) return
|
|
151
174
|
const name = room.presence?.users?.find(u => u.id === userId)?.name
|
|
152
|
-
showTyping(userId, name ?? 'Someone') // clearing it after
|
|
175
|
+
showTyping(userId, name ?? 'Someone') // clearing it after ~5 seconds is yours to do
|
|
153
176
|
})
|
|
154
177
|
```
|
|
155
178
|
- **The connection comes back on its own.** It reconnects with exponential backoff, so don't
|
|
@@ -218,6 +241,12 @@ From an origin that isn't on the list it isn't just REST that fails — **the co
|
|
|
218
241
|
is a 401.** An authentication refusal is a failure the SDK doesn't retry, so the client stops
|
|
219
242
|
at `closed`, and the reason arrives on `chat.on('error')`.
|
|
220
243
|
|
|
244
|
+
**On Node (bots, tests) there is no origin to add.** The server accepts a request with **no**
|
|
245
|
+
`Origin` header without an origin check — Node's global `WebSocket` and `fetch` don't send one,
|
|
246
|
+
so they connect as is. If you set the header yourself, its value must be on the allowed list.
|
|
247
|
+
The origin list only stops another site from using your `pk_` in a visitor's browser (a `pk_` is
|
|
248
|
+
public). A user token is required everywhere.
|
|
249
|
+
|
|
221
250
|
### Errors
|
|
222
251
|
|
|
223
252
|
Failures are `ChatError`.
|
package/README.md
CHANGED
|
@@ -88,7 +88,7 @@ off()
|
|
|
88
88
|
| `reactionsOf(messageId, {emoji?, cursor?, limit?})` | 누가 눌렀는지. **한 행은 (유저, 이모지) 쌍**이라 한 사람이 여러 줄일 수 있다. `limit` 기본 50 최대 100, 마지막 페이지의 `cursor`는 빈 문자열 |
|
|
89
89
|
| `markRead(seq, {threadId?})` | 읽음 커서 |
|
|
90
90
|
| `reads({userId?, cursor?, limit?})` | 읽음 커서 목록. `{reads: [{userId?, seq, threadId?, withdrawn?}], cursor}`. **`userId`로 한 사람만** — 자기 스레드별 커서를 되찾을 때 `reads({userId: chat.user.id})`. `cursor`가 `''`이면 끝 |
|
|
91
|
-
| `typing({threadId?})` | 입력 중. 던지지 않는다. 스레드 답글을 쓰는 중이면 `threadId` |
|
|
91
|
+
| `typing({threadId?})` | 입력 중. 던지지 않는다. **입력 이벤트마다 불러도 된다** — SDK가 방마다 1초에 한 번만 보낸다. 스레드 답글을 쓰는 중이면 `threadId` |
|
|
92
92
|
| `join()` / `leave()` | 멤버십 |
|
|
93
93
|
| `presenceList()` | 지금 이 방에 있는 사람 |
|
|
94
94
|
|
|
@@ -96,10 +96,10 @@ off()
|
|
|
96
96
|
|
|
97
97
|
| 이벤트 | 페이로드 |
|
|
98
98
|
|---|---|
|
|
99
|
-
| `message.created` / `message.updated` | `Message`. `created`에는 `thread`가 없고 `reactions`가 비어
|
|
99
|
+
| `message.created` / `message.updated` | `Message`. `created`에는 `thread`가 없고 `reactions`가 비어 있으며, `myReactions`는 **SDK가 `[]`로 채운다**(와이어에는 없다) |
|
|
100
100
|
| `message.deleted` | `{id, seq}`. `seq`는 그 메시지가 **발행될 때** 받은 값이다 |
|
|
101
101
|
| `reaction.added` / `reaction.removed` | `{messageId, emoji, count, userId?}`. SDK가 `messages` 안의 그 행의 `reactions` 개수를(내 것이면 `myReactions`도) 이미 고쳐 두었다. `history()`로 따로 읽은 행처럼 **목록 밖의 행은 소비자가 고친다** |
|
|
102
|
-
| `thread.updated` | `{rootId, count, lastSeq?, lastAt?}` |
|
|
102
|
+
| `thread.updated` | `{rootId, count, lastSeq?, lastAt?}`. SDK가 `messages` 안의 **루트 행 `thread`**(`count`·`lastSeq`·`lastAt`)를 이미 고쳐 두었다. 목록 밖의 루트는 소비자가 고친다 |
|
|
103
103
|
| `presence` | `{count, joined?, left?, users?, capped?}`. `joined`/`left`는 증분, `users`는 교체다 |
|
|
104
104
|
| `typing` | `{userId, threadId?}` — `threadId`는 스레드 **루트** id, 본 타임라인이면 없다 |
|
|
105
105
|
| `read` | `{userId, seq, threadId?}` |
|
|
@@ -137,16 +137,33 @@ room.on('messages', m => (messages.value = m))
|
|
|
137
137
|
- **`reset`을 무시하면 안 된다.** 옛 목록에 이어 붙이면 아무도 메우지 않는 구멍이 남는다.
|
|
138
138
|
- **과거는 `loadOlder()`로 같은 목록에 붙인다.** `history()`는 목록을 건드리지 않는 직접
|
|
139
139
|
읽기이므로 합치고 중복을 거르는 일이 소비자 몫이 된다.
|
|
140
|
+
- **리액션 칩은 `reactions`와 `myReactions`를 합쳐 그린다.** `react()`는 `myReactions`를 먼저 옮기고
|
|
141
|
+
개수는 `reaction.added`를 기다리므로, 처음 다는 이모지는 잠깐 `myReactions`에만 있다. 그 칩은
|
|
142
|
+
**강조한 이모지만**(개수 없이) 그리고, `1`을 지어내지 않는다 — 그 사이 남이 눌렀으면 틀린 숫자다.
|
|
143
|
+
- **이모지 종류에는 메시지당 상한이 있다**(`hello.limits.maxDistinctEmojiPerMessage`, 기본 20). 넘는 새
|
|
144
|
+
이모지는 `invalid`로 거절되고 SDK가 `myReactions`를 되돌린다. 이미 달린 이모지를 누르는 것은 상한과
|
|
145
|
+
무관하다. 피커를 막으려면 `reactions.length`가 상한에 닿았고 그 이모지가 없을 때 비활성화한다.
|
|
146
|
+
- **스레드 패널은 두 곳을 합친다.** `messages`에는 SDK가 읽은 구간의 답글만 있다(방 전체 스트림이라
|
|
147
|
+
오래된 스레드의 답글은 없다). 지난 답글은 `history({view: {thread: rootId}})`로 읽고, 새 답글은
|
|
148
|
+
`messages`에서 `threadId === rootId`로 골라 **id로 합친다.** `history()`로 읽은 행은 목록 밖이라
|
|
149
|
+
`reaction.added`/`removed`(개수, 내 `userId`면 `myReactions`)와 `message.updated`·`message.deleted`를
|
|
150
|
+
**소비자가 직접 반영한다** — 빠뜨리면 지난 답글만 리액션이 멈춰 보인다. `reset`이면 다시 읽는다.
|
|
140
151
|
- **`typing`은 보낸 사람에게도 온다.** "X가 입력 중"을 그린다면 자기 `userId`를 건너뛴다.
|
|
141
152
|
- **`typing`은 이름을 싣지 않는다.** 이름은 `room.presence.users`에서 찾는다 — 방을 보고 있는
|
|
142
153
|
사람이 거기 있다. 메시지 발신자에서 이름을 모으면 아직 말하지 않은 사람을 모른다.
|
|
143
154
|
`users`가 없으면(100명 넘는 방) `presenceList()`로 한 번 받아 오고, 그래도 없으면 대체 이름을 쓴다.
|
|
155
|
+
- **`typing`은 한 사람당 방마다 많아야 3초에 한 번 온다.** "입력 멈춤" 이벤트는 없으니 표시는
|
|
156
|
+
마지막 이벤트 뒤 **5초 이상** 유지한다 — 계속 입력하는 사람의 방송 간격도 4초를 넘을 수 있어서,
|
|
157
|
+
그보다 짧으면 이벤트 사이에서 깜빡인다.
|
|
158
|
+
- **방마다 한 번에 알리는 사람 수에 상한이 있다**(지금 3명). 방송 한 번이 인원수만큼 나가기
|
|
159
|
+
때문이고, 화면도 "A, B, C가 입력 중" 정도까지만 그린다. 붐비는 방에서는 입력 중인데 알려지지
|
|
160
|
+
않는 사람이 있다 — 그 숫자에 기대는 코드는 짜지 않는다(엔진이 바꿀 수 있다).
|
|
144
161
|
|
|
145
162
|
```ts
|
|
146
163
|
room.on('typing', ({ userId }) => {
|
|
147
164
|
if (userId === chat.user?.id) return
|
|
148
165
|
const name = room.presence?.users?.find(u => u.id === userId)?.name
|
|
149
|
-
showTyping(userId, name ?? '누군가') //
|
|
166
|
+
showTyping(userId, name ?? '누군가') // 5초쯤 뒤 지우는 것은 소비자 몫이다
|
|
150
167
|
})
|
|
151
168
|
```
|
|
152
169
|
- **연결은 알아서 돌아온다.** 끊기면 지수 백오프로 다시 붙으니 재시도 루프를 짜지 않는다.
|
|
@@ -207,6 +224,11 @@ for (const part of splitByUrl(text)) {
|
|
|
207
224
|
목록에 없는 오리진에서는 REST만이 아니라 **접속부터 401이다.** 인증 거절은 SDK가 다시
|
|
208
225
|
시도하지 않으므로 클라이언트가 `closed`에서 멈추고, 이유는 `chat.on('error')`로 온다.
|
|
209
226
|
|
|
227
|
+
**Node(봇·테스트)에서는 오리진을 넣지 않는다.** 서버는 `Origin` 헤더가 **없는** 요청을 오리진
|
|
228
|
+
검사 없이 받는다 — Node의 전역 `WebSocket`·`fetch`는 그 헤더를 보내지 않으므로 그대로 붙는다.
|
|
229
|
+
헤더를 직접 붙이면 그 값은 허용 오리진에 있어야 한다. 오리진 목록은 남의 사이트가 방문자의 브라우저에서
|
|
230
|
+
당신의 `pk_`를 쓰는 것만 막는다(`pk_`는 공개값이다). 유저 토큰은 어디서나 필요하다.
|
|
231
|
+
|
|
210
232
|
### 에러
|
|
211
233
|
|
|
212
234
|
실패는 `ChatError`다.
|
package/dist/index.cjs
CHANGED
|
@@ -460,13 +460,21 @@ var Timeline = class {
|
|
|
460
460
|
this.items[at] = next;
|
|
461
461
|
this.changed();
|
|
462
462
|
}
|
|
463
|
-
/**
|
|
464
|
-
|
|
463
|
+
/**
|
|
464
|
+
* Applies a `thread.updated` to the root message's aggregate.
|
|
465
|
+
*
|
|
466
|
+
* `lastAt`도 옮긴다. 히스토리 행의 `thread`는 `{count, lastSeq, lastAt}`이라,
|
|
467
|
+
* 빼고 바꾸면 "마지막 답글 3분 전"을 그리던 화면이 답글이 달리는 순간 그 값을 잃는다.
|
|
468
|
+
*/
|
|
469
|
+
thread(rootId, count, lastSeq, lastAt) {
|
|
465
470
|
const at = this.items.findIndex((m) => m.id === rootId);
|
|
466
471
|
if (at === -1) return;
|
|
467
472
|
const current = this.items[at];
|
|
473
|
+
const thread = { count };
|
|
474
|
+
if (lastSeq !== void 0) thread.lastSeq = lastSeq;
|
|
475
|
+
if (lastAt !== void 0) thread.lastAt = lastAt;
|
|
468
476
|
this.own();
|
|
469
|
-
this.items[at] = { ...current, thread
|
|
477
|
+
this.items[at] = { ...current, thread };
|
|
470
478
|
this.changed();
|
|
471
479
|
}
|
|
472
480
|
/** Applies a `message.deleted`, remembering it if the row is not here. */
|
|
@@ -613,6 +621,7 @@ function createTimeline(options) {
|
|
|
613
621
|
|
|
614
622
|
// src/room.ts
|
|
615
623
|
var HistoryPageSize = 100;
|
|
624
|
+
var TypingSendIntervalMs = 1e3;
|
|
616
625
|
var MaxRepairs = 5;
|
|
617
626
|
var RepairBaseMs = 1e3;
|
|
618
627
|
var Room = class extends Emitter {
|
|
@@ -662,6 +671,8 @@ var Room = class extends Emitter {
|
|
|
662
671
|
wanted = false;
|
|
663
672
|
/** 신원이 바뀌어 버린 목록을 다음 구독이 다시 채우고 `reset`으로 알려야 한다. */
|
|
664
673
|
rebuildPending = false;
|
|
674
|
+
/** When `typing()` last tried to send (a closed socket still spends the window). See TypingSendIntervalMs. */
|
|
675
|
+
typingSentAt = Number.NEGATIVE_INFINITY;
|
|
665
676
|
subscribing;
|
|
666
677
|
/** Self-repair: the armed retry, and how many have run since the last success. */
|
|
667
678
|
repairTimer;
|
|
@@ -922,11 +933,26 @@ var Room = class extends Emitter {
|
|
|
922
933
|
* and the main view can skip them. The server keeps one throttle slot
|
|
923
934
|
* per user per room, not per thread: switching between the main box
|
|
924
935
|
* and a thread is heard up to three seconds late.
|
|
936
|
+
*
|
|
937
|
+
* **Call it on every input event; the SDK throttles.** At most one frame
|
|
938
|
+
* leaves per room per second, and the server
|
|
939
|
+
* broadcasts at most one per three seconds. There is no "stopped"
|
|
940
|
+
* event, so show the indicator for five seconds or more after
|
|
941
|
+
* the last one: the gap between one person's broadcasts is three
|
|
942
|
+
* seconds plus this throttle plus the wait for their next keystroke,
|
|
943
|
+
* and longer in a busy room. Anything shorter blinks between signals.
|
|
944
|
+
*
|
|
945
|
+
* The server also caps how many people one room announces per window
|
|
946
|
+
* (a screen draws "A, B and C are typing" at most), so in a busy room
|
|
947
|
+
* some typists are never announced.
|
|
925
948
|
*/
|
|
926
949
|
typing(options = {}) {
|
|
950
|
+
const now = Date.now();
|
|
951
|
+
if (now >= this.typingSentAt && now - this.typingSentAt < TypingSendIntervalMs) return;
|
|
927
952
|
try {
|
|
928
953
|
const data = { roomId: this.requireId("typing") };
|
|
929
954
|
if (options.threadId !== void 0) data["threadId"] = options.threadId;
|
|
955
|
+
this.typingSentAt = now;
|
|
930
956
|
void this.chat.sendFrame("typing", data, void 0, { wait: false }).catch(() => {
|
|
931
957
|
});
|
|
932
958
|
} catch {
|
|
@@ -1083,6 +1109,7 @@ var Room = class extends Emitter {
|
|
|
1083
1109
|
switch (type) {
|
|
1084
1110
|
case "message.created":
|
|
1085
1111
|
if (data.seq > this.lastSeq) this.lastSeq = data.seq;
|
|
1112
|
+
if (data.myReactions === void 0) data = { ...data, myReactions: [] };
|
|
1086
1113
|
this.timeline.add(data).catch((err) => {
|
|
1087
1114
|
this.subscribed = false;
|
|
1088
1115
|
this.failed(err);
|
|
@@ -1107,7 +1134,7 @@ var Room = class extends Emitter {
|
|
|
1107
1134
|
}
|
|
1108
1135
|
case "thread.updated": {
|
|
1109
1136
|
const t = data;
|
|
1110
|
-
this.timeline.thread(t.rootId, t.count, t.lastSeq);
|
|
1137
|
+
this.timeline.thread(t.rootId, t.count, t.lastSeq, t.lastAt);
|
|
1111
1138
|
break;
|
|
1112
1139
|
}
|
|
1113
1140
|
case "presence":
|
package/dist/index.d.cts
CHANGED
|
@@ -190,18 +190,25 @@ type Message = {
|
|
|
190
190
|
* Filled by history reads and kept in step by the SDK afterwards: a
|
|
191
191
|
* `reaction.*` event whose `userId` is `chat.user.id` updates it, and
|
|
192
192
|
* this client's own `react()`/`unreact()` update it **before the frame
|
|
193
|
-
* goes out**, rolling back if the server refuses.
|
|
194
|
-
*
|
|
195
|
-
*
|
|
193
|
+
* goes out**, rolling back if the server refuses. A live
|
|
194
|
+
* `message.created` carries none on the wire (a room frame is the same
|
|
195
|
+
* bytes for every viewer), so the SDK fills it with `[]`: a message
|
|
196
|
+
* that was just published has no reactions, and an absent field reads
|
|
197
|
+
* as "no viewer", which is what it means on a REST row.
|
|
196
198
|
*
|
|
197
199
|
* The SDK owns this field, so a consumer does not need -- and should
|
|
198
200
|
* not add -- an optimistic layer of its own on top of it. The count in
|
|
199
201
|
* `reactions` is the opposite: always the server's, never moved locally.
|
|
200
202
|
*/
|
|
201
203
|
myReactions?: string[];
|
|
204
|
+
/**
|
|
205
|
+
* The root's reply summary. The SDK keeps it current from
|
|
206
|
+
* `thread.updated` (count, `lastSeq`, `lastAt`) on rows in `messages`.
|
|
207
|
+
*/
|
|
202
208
|
thread?: {
|
|
203
209
|
count: number;
|
|
204
210
|
lastSeq?: number;
|
|
211
|
+
lastAt?: number;
|
|
205
212
|
};
|
|
206
213
|
};
|
|
207
214
|
type ReactionUser = {
|
|
@@ -401,6 +408,8 @@ declare class Room extends Emitter<RoomEvents> {
|
|
|
401
408
|
private wanted;
|
|
402
409
|
/** 신원이 바뀌어 버린 목록을 다음 구독이 다시 채우고 `reset`으로 알려야 한다. */
|
|
403
410
|
private rebuildPending;
|
|
411
|
+
/** When `typing()` last tried to send (a closed socket still spends the window). See TypingSendIntervalMs. */
|
|
412
|
+
private typingSentAt;
|
|
404
413
|
private subscribing;
|
|
405
414
|
/** Self-repair: the armed retry, and how many have run since the last success. */
|
|
406
415
|
private repairTimer;
|
|
@@ -578,6 +587,18 @@ declare class Room extends Emitter<RoomEvents> {
|
|
|
578
587
|
* and the main view can skip them. The server keeps one throttle slot
|
|
579
588
|
* per user per room, not per thread: switching between the main box
|
|
580
589
|
* and a thread is heard up to three seconds late.
|
|
590
|
+
*
|
|
591
|
+
* **Call it on every input event; the SDK throttles.** At most one frame
|
|
592
|
+
* leaves per room per second, and the server
|
|
593
|
+
* broadcasts at most one per three seconds. There is no "stopped"
|
|
594
|
+
* event, so show the indicator for five seconds or more after
|
|
595
|
+
* the last one: the gap between one person's broadcasts is three
|
|
596
|
+
* seconds plus this throttle plus the wait for their next keystroke,
|
|
597
|
+
* and longer in a busy room. Anything shorter blinks between signals.
|
|
598
|
+
*
|
|
599
|
+
* The server also caps how many people one room announces per window
|
|
600
|
+
* (a screen draws "A, B and C are typing" at most), so in a busy room
|
|
601
|
+
* some typists are never announced.
|
|
581
602
|
*/
|
|
582
603
|
typing(options?: {
|
|
583
604
|
threadId?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -190,18 +190,25 @@ type Message = {
|
|
|
190
190
|
* Filled by history reads and kept in step by the SDK afterwards: a
|
|
191
191
|
* `reaction.*` event whose `userId` is `chat.user.id` updates it, and
|
|
192
192
|
* this client's own `react()`/`unreact()` update it **before the frame
|
|
193
|
-
* goes out**, rolling back if the server refuses.
|
|
194
|
-
*
|
|
195
|
-
*
|
|
193
|
+
* goes out**, rolling back if the server refuses. A live
|
|
194
|
+
* `message.created` carries none on the wire (a room frame is the same
|
|
195
|
+
* bytes for every viewer), so the SDK fills it with `[]`: a message
|
|
196
|
+
* that was just published has no reactions, and an absent field reads
|
|
197
|
+
* as "no viewer", which is what it means on a REST row.
|
|
196
198
|
*
|
|
197
199
|
* The SDK owns this field, so a consumer does not need -- and should
|
|
198
200
|
* not add -- an optimistic layer of its own on top of it. The count in
|
|
199
201
|
* `reactions` is the opposite: always the server's, never moved locally.
|
|
200
202
|
*/
|
|
201
203
|
myReactions?: string[];
|
|
204
|
+
/**
|
|
205
|
+
* The root's reply summary. The SDK keeps it current from
|
|
206
|
+
* `thread.updated` (count, `lastSeq`, `lastAt`) on rows in `messages`.
|
|
207
|
+
*/
|
|
202
208
|
thread?: {
|
|
203
209
|
count: number;
|
|
204
210
|
lastSeq?: number;
|
|
211
|
+
lastAt?: number;
|
|
205
212
|
};
|
|
206
213
|
};
|
|
207
214
|
type ReactionUser = {
|
|
@@ -401,6 +408,8 @@ declare class Room extends Emitter<RoomEvents> {
|
|
|
401
408
|
private wanted;
|
|
402
409
|
/** 신원이 바뀌어 버린 목록을 다음 구독이 다시 채우고 `reset`으로 알려야 한다. */
|
|
403
410
|
private rebuildPending;
|
|
411
|
+
/** When `typing()` last tried to send (a closed socket still spends the window). See TypingSendIntervalMs. */
|
|
412
|
+
private typingSentAt;
|
|
404
413
|
private subscribing;
|
|
405
414
|
/** Self-repair: the armed retry, and how many have run since the last success. */
|
|
406
415
|
private repairTimer;
|
|
@@ -578,6 +587,18 @@ declare class Room extends Emitter<RoomEvents> {
|
|
|
578
587
|
* and the main view can skip them. The server keeps one throttle slot
|
|
579
588
|
* per user per room, not per thread: switching between the main box
|
|
580
589
|
* and a thread is heard up to three seconds late.
|
|
590
|
+
*
|
|
591
|
+
* **Call it on every input event; the SDK throttles.** At most one frame
|
|
592
|
+
* leaves per room per second, and the server
|
|
593
|
+
* broadcasts at most one per three seconds. There is no "stopped"
|
|
594
|
+
* event, so show the indicator for five seconds or more after
|
|
595
|
+
* the last one: the gap between one person's broadcasts is three
|
|
596
|
+
* seconds plus this throttle plus the wait for their next keystroke,
|
|
597
|
+
* and longer in a busy room. Anything shorter blinks between signals.
|
|
598
|
+
*
|
|
599
|
+
* The server also caps how many people one room announces per window
|
|
600
|
+
* (a screen draws "A, B and C are typing" at most), so in a busy room
|
|
601
|
+
* some typists are never announced.
|
|
581
602
|
*/
|
|
582
603
|
typing(options?: {
|
|
583
604
|
threadId?: string;
|
package/dist/index.js
CHANGED
|
@@ -390,13 +390,21 @@ var Timeline = class {
|
|
|
390
390
|
this.items[at] = next;
|
|
391
391
|
this.changed();
|
|
392
392
|
}
|
|
393
|
-
/**
|
|
394
|
-
|
|
393
|
+
/**
|
|
394
|
+
* Applies a `thread.updated` to the root message's aggregate.
|
|
395
|
+
*
|
|
396
|
+
* `lastAt`도 옮긴다. 히스토리 행의 `thread`는 `{count, lastSeq, lastAt}`이라,
|
|
397
|
+
* 빼고 바꾸면 "마지막 답글 3분 전"을 그리던 화면이 답글이 달리는 순간 그 값을 잃는다.
|
|
398
|
+
*/
|
|
399
|
+
thread(rootId, count, lastSeq, lastAt) {
|
|
395
400
|
const at = this.items.findIndex((m) => m.id === rootId);
|
|
396
401
|
if (at === -1) return;
|
|
397
402
|
const current = this.items[at];
|
|
403
|
+
const thread = { count };
|
|
404
|
+
if (lastSeq !== void 0) thread.lastSeq = lastSeq;
|
|
405
|
+
if (lastAt !== void 0) thread.lastAt = lastAt;
|
|
398
406
|
this.own();
|
|
399
|
-
this.items[at] = { ...current, thread
|
|
407
|
+
this.items[at] = { ...current, thread };
|
|
400
408
|
this.changed();
|
|
401
409
|
}
|
|
402
410
|
/** Applies a `message.deleted`, remembering it if the row is not here. */
|
|
@@ -543,6 +551,7 @@ function createTimeline(options) {
|
|
|
543
551
|
|
|
544
552
|
// src/room.ts
|
|
545
553
|
var HistoryPageSize = 100;
|
|
554
|
+
var TypingSendIntervalMs = 1e3;
|
|
546
555
|
var MaxRepairs = 5;
|
|
547
556
|
var RepairBaseMs = 1e3;
|
|
548
557
|
var Room = class extends Emitter {
|
|
@@ -592,6 +601,8 @@ var Room = class extends Emitter {
|
|
|
592
601
|
wanted = false;
|
|
593
602
|
/** 신원이 바뀌어 버린 목록을 다음 구독이 다시 채우고 `reset`으로 알려야 한다. */
|
|
594
603
|
rebuildPending = false;
|
|
604
|
+
/** When `typing()` last tried to send (a closed socket still spends the window). See TypingSendIntervalMs. */
|
|
605
|
+
typingSentAt = Number.NEGATIVE_INFINITY;
|
|
595
606
|
subscribing;
|
|
596
607
|
/** Self-repair: the armed retry, and how many have run since the last success. */
|
|
597
608
|
repairTimer;
|
|
@@ -852,11 +863,26 @@ var Room = class extends Emitter {
|
|
|
852
863
|
* and the main view can skip them. The server keeps one throttle slot
|
|
853
864
|
* per user per room, not per thread: switching between the main box
|
|
854
865
|
* and a thread is heard up to three seconds late.
|
|
866
|
+
*
|
|
867
|
+
* **Call it on every input event; the SDK throttles.** At most one frame
|
|
868
|
+
* leaves per room per second, and the server
|
|
869
|
+
* broadcasts at most one per three seconds. There is no "stopped"
|
|
870
|
+
* event, so show the indicator for five seconds or more after
|
|
871
|
+
* the last one: the gap between one person's broadcasts is three
|
|
872
|
+
* seconds plus this throttle plus the wait for their next keystroke,
|
|
873
|
+
* and longer in a busy room. Anything shorter blinks between signals.
|
|
874
|
+
*
|
|
875
|
+
* The server also caps how many people one room announces per window
|
|
876
|
+
* (a screen draws "A, B and C are typing" at most), so in a busy room
|
|
877
|
+
* some typists are never announced.
|
|
855
878
|
*/
|
|
856
879
|
typing(options = {}) {
|
|
880
|
+
const now = Date.now();
|
|
881
|
+
if (now >= this.typingSentAt && now - this.typingSentAt < TypingSendIntervalMs) return;
|
|
857
882
|
try {
|
|
858
883
|
const data = { roomId: this.requireId("typing") };
|
|
859
884
|
if (options.threadId !== void 0) data["threadId"] = options.threadId;
|
|
885
|
+
this.typingSentAt = now;
|
|
860
886
|
void this.chat.sendFrame("typing", data, void 0, { wait: false }).catch(() => {
|
|
861
887
|
});
|
|
862
888
|
} catch {
|
|
@@ -1013,6 +1039,7 @@ var Room = class extends Emitter {
|
|
|
1013
1039
|
switch (type) {
|
|
1014
1040
|
case "message.created":
|
|
1015
1041
|
if (data.seq > this.lastSeq) this.lastSeq = data.seq;
|
|
1042
|
+
if (data.myReactions === void 0) data = { ...data, myReactions: [] };
|
|
1016
1043
|
this.timeline.add(data).catch((err) => {
|
|
1017
1044
|
this.subscribed = false;
|
|
1018
1045
|
this.failed(err);
|
|
@@ -1037,7 +1064,7 @@ var Room = class extends Emitter {
|
|
|
1037
1064
|
}
|
|
1038
1065
|
case "thread.updated": {
|
|
1039
1066
|
const t = data;
|
|
1040
|
-
this.timeline.thread(t.rootId, t.count, t.lastSeq);
|
|
1067
|
+
this.timeline.thread(t.rootId, t.count, t.lastSeq, t.lastAt);
|
|
1041
1068
|
break;
|
|
1042
1069
|
}
|
|
1043
1070
|
case "presence":
|