Skip to content

Commit 287c29f

Browse files
authored
Fix legacy message encoding (#1173)
1 parent 992cdfd commit 287c29f

File tree

5 files changed

+57
-24
lines changed

5 files changed

+57
-24
lines changed

.changeset/dull-peas-prove.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@livekit/components-core": patch
3+
---
4+
5+
Fix legacy message encoding

examples/nextjs/pages/minimal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { useMemo } from 'react';
88
const MinimalExample: NextPage = () => {
99
const params = typeof window !== 'undefined' ? new URLSearchParams(location.search) : null;
1010
const roomName = params?.get('room') ?? 'test-room';
11-
setLogLevel('info', { liveKitClientLogLevel: 'warn' });
11+
setLogLevel('debug', { liveKitClientLogLevel: 'info' });
1212

1313
const tokenOptions = useMemo(() => {
1414
const userId = params?.get('user') ?? generateRandomUserId();

packages/core/src/components/chat.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function isIgnorableChatMessage(msg: ReceivedChatMessage | LegacyReceivedChatMes
5656
const decodeLegacyMsg = (message: Uint8Array) =>
5757
JSON.parse(new TextDecoder().decode(message)) as LegacyReceivedChatMessage | ReceivedChatMessage;
5858

59-
const encodeLegacyMsg = (message: LegacyReceivedChatMessage) =>
59+
const encodeLegacyMsg = (message: LegacyChatMessage) =>
6060
new TextEncoder().encode(JSON.stringify(message));
6161

6262
export function setupChat(room: Room, options?: ChatOptions) {
@@ -154,18 +154,30 @@ export function setupChat(room: Room, options?: ChatOptions) {
154154

155155
try {
156156
const info = await room.localParticipant.sendText(message, options);
157-
const chatMsg: ReceivedChatMessage = {
157+
158+
const legacyChatMsg: LegacyChatMessage = {
158159
id: info.id,
159160
timestamp: Date.now(),
160161
message,
161-
from: room.localParticipant,
162+
};
163+
164+
const chatMsg: ChatMessage = {
165+
...legacyChatMsg,
162166
attachedFiles: options.attachments,
163167
};
164-
messageSubject.next(chatMsg);
165-
const encodedLegacyMsg = finalMessageEncoder({
168+
169+
const receivedChatMsg: ReceivedChatMessage = {
166170
...chatMsg,
171+
from: room.localParticipant,
172+
};
173+
174+
messageSubject.next(receivedChatMsg);
175+
176+
const encodedLegacyMsg = finalMessageEncoder({
177+
...legacyChatMsg,
167178
ignoreLegacy: serverSupportsDataStreams(),
168179
});
180+
169181
try {
170182
await sendMessage(room.localParticipant, encodedLegacyMsg, {
171183
reliable: true,
@@ -174,7 +186,8 @@ export function setupChat(room: Room, options?: ChatOptions) {
174186
} catch (error) {
175187
log.info('could not send message in legacy chat format', error);
176188
}
177-
return chatMsg;
189+
190+
return receivedChatMsg;
178191
} finally {
179192
isSending$.next(false);
180193
}

pnpm-lock.yaml

Lines changed: 31 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ packages:
55
- 'tooling/*'
66

77
catalog:
8-
livekit-client: ^2.13.1
8+
livekit-client: ^2.13.3

0 commit comments

Comments
 (0)