@kispi/chat 0.7.0 → 0.7.1

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 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
 
@@ -144,12 +144,20 @@ room.on('messages', m => (messages.value = m))
144
144
  watching the room is there. Collecting names from message senders misses anyone who has not
145
145
  spoken yet. If `users` is absent (a room over 100), fetch it once with `presenceList()`, and fall
146
146
  back to a placeholder if the name is still missing.
147
+ - **`typing` arrives at most once per person per room every three seconds.** There is no
148
+ "stopped" event, so keep the indicator for **five seconds or more** after the last one — even
149
+ someone typing steadily can be broadcast more than four seconds apart, and anything shorter
150
+ blinks between events.
151
+ - **Each room announces only a few typists at a time** (three today). Every broadcast goes out
152
+ once per person in the room, and a screen draws "A, B and C are typing" at most anyway. In a
153
+ busy room some people typing are never announced — don't write code that depends on the number
154
+ (the engine may change it).
147
155
 
148
156
  ```ts
149
157
  room.on('typing', ({ userId }) => {
150
158
  if (userId === chat.user?.id) return
151
159
  const name = room.presence?.users?.find(u => u.id === userId)?.name
152
- showTyping(userId, name ?? 'Someone') // clearing it after a few seconds is yours to do
160
+ showTyping(userId, name ?? 'Someone') // clearing it after ~5 seconds is yours to do
153
161
  })
154
162
  ```
155
163
  - **The connection comes back on its own.** It reconnects with exponential backoff, so don't
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
 
@@ -141,12 +141,18 @@ room.on('messages', m => (messages.value = m))
141
141
  - **`typing`은 이름을 싣지 않는다.** 이름은 `room.presence.users`에서 찾는다 — 방을 보고 있는
142
142
  사람이 거기 있다. 메시지 발신자에서 이름을 모으면 아직 말하지 않은 사람을 모른다.
143
143
  `users`가 없으면(100명 넘는 방) `presenceList()`로 한 번 받아 오고, 그래도 없으면 대체 이름을 쓴다.
144
+ - **`typing`은 한 사람당 방마다 많아야 3초에 한 번 온다.** "입력 멈춤" 이벤트는 없으니 표시는
145
+ 마지막 이벤트 뒤 **5초 이상** 유지한다 — 계속 입력하는 사람의 방송 간격도 4초를 넘을 수 있어서,
146
+ 그보다 짧으면 이벤트 사이에서 깜빡인다.
147
+ - **방마다 한 번에 알리는 사람 수에 상한이 있다**(지금 3명). 방송 한 번이 인원수만큼 나가기
148
+ 때문이고, 화면도 "A, B, C가 입력 중" 정도까지만 그린다. 붐비는 방에서는 입력 중인데 알려지지
149
+ 않는 사람이 있다 — 그 숫자에 기대는 코드는 짜지 않는다(엔진이 바꿀 수 있다).
144
150
 
145
151
  ```ts
146
152
  room.on('typing', ({ userId }) => {
147
153
  if (userId === chat.user?.id) return
148
154
  const name = room.presence?.users?.find(u => u.id === userId)?.name
149
- showTyping(userId, name ?? '누군가') // 몇 초 뒤 지우는 것은 소비자 몫이다
155
+ showTyping(userId, name ?? '누군가') // 5초쯤 뒤 지우는 것은 소비자 몫이다
150
156
  })
151
157
  ```
152
158
  - **연결은 알아서 돌아온다.** 끊기면 지수 백오프로 다시 붙으니 재시도 루프를 짜지 않는다.
package/dist/index.cjs CHANGED
@@ -613,6 +613,7 @@ function createTimeline(options) {
613
613
 
614
614
  // src/room.ts
615
615
  var HistoryPageSize = 100;
616
+ var TypingSendIntervalMs = 1e3;
616
617
  var MaxRepairs = 5;
617
618
  var RepairBaseMs = 1e3;
618
619
  var Room = class extends Emitter {
@@ -662,6 +663,8 @@ var Room = class extends Emitter {
662
663
  wanted = false;
663
664
  /** 신원이 바뀌어 버린 목록을 다음 구독이 다시 채우고 `reset`으로 알려야 한다. */
664
665
  rebuildPending = false;
666
+ /** When `typing()` last tried to send (a closed socket still spends the window). See TypingSendIntervalMs. */
667
+ typingSentAt = Number.NEGATIVE_INFINITY;
665
668
  subscribing;
666
669
  /** Self-repair: the armed retry, and how many have run since the last success. */
667
670
  repairTimer;
@@ -922,11 +925,26 @@ var Room = class extends Emitter {
922
925
  * and the main view can skip them. The server keeps one throttle slot
923
926
  * per user per room, not per thread: switching between the main box
924
927
  * and a thread is heard up to three seconds late.
928
+ *
929
+ * **Call it on every input event; the SDK throttles.** At most one frame
930
+ * leaves per room per second, and the server
931
+ * broadcasts at most one per three seconds. There is no "stopped"
932
+ * event, so show the indicator for five seconds or more after
933
+ * the last one: the gap between one person's broadcasts is three
934
+ * seconds plus this throttle plus the wait for their next keystroke,
935
+ * and longer in a busy room. Anything shorter blinks between signals.
936
+ *
937
+ * The server also caps how many people one room announces per window
938
+ * (a screen draws "A, B and C are typing" at most), so in a busy room
939
+ * some typists are never announced.
925
940
  */
926
941
  typing(options = {}) {
942
+ const now = Date.now();
943
+ if (now >= this.typingSentAt && now - this.typingSentAt < TypingSendIntervalMs) return;
927
944
  try {
928
945
  const data = { roomId: this.requireId("typing") };
929
946
  if (options.threadId !== void 0) data["threadId"] = options.threadId;
947
+ this.typingSentAt = now;
930
948
  void this.chat.sendFrame("typing", data, void 0, { wait: false }).catch(() => {
931
949
  });
932
950
  } catch {
package/dist/index.d.cts CHANGED
@@ -401,6 +401,8 @@ declare class Room extends Emitter<RoomEvents> {
401
401
  private wanted;
402
402
  /** 신원이 바뀌어 버린 목록을 다음 구독이 다시 채우고 `reset`으로 알려야 한다. */
403
403
  private rebuildPending;
404
+ /** When `typing()` last tried to send (a closed socket still spends the window). See TypingSendIntervalMs. */
405
+ private typingSentAt;
404
406
  private subscribing;
405
407
  /** Self-repair: the armed retry, and how many have run since the last success. */
406
408
  private repairTimer;
@@ -578,6 +580,18 @@ declare class Room extends Emitter<RoomEvents> {
578
580
  * and the main view can skip them. The server keeps one throttle slot
579
581
  * per user per room, not per thread: switching between the main box
580
582
  * and a thread is heard up to three seconds late.
583
+ *
584
+ * **Call it on every input event; the SDK throttles.** At most one frame
585
+ * leaves per room per second, and the server
586
+ * broadcasts at most one per three seconds. There is no "stopped"
587
+ * event, so show the indicator for five seconds or more after
588
+ * the last one: the gap between one person's broadcasts is three
589
+ * seconds plus this throttle plus the wait for their next keystroke,
590
+ * and longer in a busy room. Anything shorter blinks between signals.
591
+ *
592
+ * The server also caps how many people one room announces per window
593
+ * (a screen draws "A, B and C are typing" at most), so in a busy room
594
+ * some typists are never announced.
581
595
  */
582
596
  typing(options?: {
583
597
  threadId?: string;
package/dist/index.d.ts CHANGED
@@ -401,6 +401,8 @@ declare class Room extends Emitter<RoomEvents> {
401
401
  private wanted;
402
402
  /** 신원이 바뀌어 버린 목록을 다음 구독이 다시 채우고 `reset`으로 알려야 한다. */
403
403
  private rebuildPending;
404
+ /** When `typing()` last tried to send (a closed socket still spends the window). See TypingSendIntervalMs. */
405
+ private typingSentAt;
404
406
  private subscribing;
405
407
  /** Self-repair: the armed retry, and how many have run since the last success. */
406
408
  private repairTimer;
@@ -578,6 +580,18 @@ declare class Room extends Emitter<RoomEvents> {
578
580
  * and the main view can skip them. The server keeps one throttle slot
579
581
  * per user per room, not per thread: switching between the main box
580
582
  * and a thread is heard up to three seconds late.
583
+ *
584
+ * **Call it on every input event; the SDK throttles.** At most one frame
585
+ * leaves per room per second, and the server
586
+ * broadcasts at most one per three seconds. There is no "stopped"
587
+ * event, so show the indicator for five seconds or more after
588
+ * the last one: the gap between one person's broadcasts is three
589
+ * seconds plus this throttle plus the wait for their next keystroke,
590
+ * and longer in a busy room. Anything shorter blinks between signals.
591
+ *
592
+ * The server also caps how many people one room announces per window
593
+ * (a screen draws "A, B and C are typing" at most), so in a busy room
594
+ * some typists are never announced.
581
595
  */
582
596
  typing(options?: {
583
597
  threadId?: string;
package/dist/index.js CHANGED
@@ -543,6 +543,7 @@ function createTimeline(options) {
543
543
 
544
544
  // src/room.ts
545
545
  var HistoryPageSize = 100;
546
+ var TypingSendIntervalMs = 1e3;
546
547
  var MaxRepairs = 5;
547
548
  var RepairBaseMs = 1e3;
548
549
  var Room = class extends Emitter {
@@ -592,6 +593,8 @@ var Room = class extends Emitter {
592
593
  wanted = false;
593
594
  /** 신원이 바뀌어 버린 목록을 다음 구독이 다시 채우고 `reset`으로 알려야 한다. */
594
595
  rebuildPending = false;
596
+ /** When `typing()` last tried to send (a closed socket still spends the window). See TypingSendIntervalMs. */
597
+ typingSentAt = Number.NEGATIVE_INFINITY;
595
598
  subscribing;
596
599
  /** Self-repair: the armed retry, and how many have run since the last success. */
597
600
  repairTimer;
@@ -852,11 +855,26 @@ var Room = class extends Emitter {
852
855
  * and the main view can skip them. The server keeps one throttle slot
853
856
  * per user per room, not per thread: switching between the main box
854
857
  * and a thread is heard up to three seconds late.
858
+ *
859
+ * **Call it on every input event; the SDK throttles.** At most one frame
860
+ * leaves per room per second, and the server
861
+ * broadcasts at most one per three seconds. There is no "stopped"
862
+ * event, so show the indicator for five seconds or more after
863
+ * the last one: the gap between one person's broadcasts is three
864
+ * seconds plus this throttle plus the wait for their next keystroke,
865
+ * and longer in a busy room. Anything shorter blinks between signals.
866
+ *
867
+ * The server also caps how many people one room announces per window
868
+ * (a screen draws "A, B and C are typing" at most), so in a busy room
869
+ * some typists are never announced.
855
870
  */
856
871
  typing(options = {}) {
872
+ const now = Date.now();
873
+ if (now >= this.typingSentAt && now - this.typingSentAt < TypingSendIntervalMs) return;
857
874
  try {
858
875
  const data = { roomId: this.requireId("typing") };
859
876
  if (options.threadId !== void 0) data["threadId"] = options.threadId;
877
+ this.typingSentAt = now;
860
878
  void this.chat.sendFrame("typing", data, void 0, { wait: false }).catch(() => {
861
879
  });
862
880
  } catch {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kispi/chat",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "Client SDK for the chat server: one WebSocket, many rooms, ordered history.",
5
5
  "license": "MIT",
6
6
  "type": "module",