Skip to content

Commit d4d26e5

Browse files
committed
Add clientId usage for detecting user
1 parent ee0a785 commit d4d26e5

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

app/component/AblyBaseComponent.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ export default class AblyBaseComponent extends HTMLElement {
1515
connectToAblyChannel() {
1616
const ablyApiKey = this.getAttribute("data-api-key");
1717
const ablyTokenUrl = this.getAttribute("data-get-token-url");
18-
const ablyConfig = ablyApiKey ? ablyApiKey : { authUrl: ablyTokenUrl };
18+
let ablyConfig = {};
19+
if (ablyApiKey) {
20+
ablyConfig['key'] = ablyApiKey;
21+
} else {
22+
ablyConfig['authUrl'] = ablyTokenUrl;
23+
}
1924

2025
this.ably = new Ably.Realtime(ablyConfig);
2126
this.subscribedChannels = [];

app/component/AblyChatComponent.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,16 @@ export default class AblyChat extends AblyBaseComponent {
8989
}
9090
}
9191

92-
formatMessages(messages) {
92+
formatMessages(messages) {
9393
const messageMarkup = messages.map((message, index) => {
94-
const author = message.connectionId === this.ably.connection.id ? "me" : "other";
94+
const clientId = message.clientId;
95+
let author;
96+
if (clientId) {
97+
author = this.ably.auth.clientId === clientId ? "me" : clientId;
98+
} else {
99+
author = message.connectionId === this.ably.connection.id ? "me" : "other";
100+
}
101+
95102
return `<span class="message" data-author=${author}>${message.data}</span>`;
96103
});
97104

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ably-chat-component",
3-
"version": "1.0.8",
3+
"version": "1.0.9",
44
"description": "Real time chat from Ably - just add your own API key!",
55
"main": "build/index.js",
66
"exports": {

0 commit comments

Comments
 (0)