Skip to content

Update Vue, Angular, Svelte getting started examples to use the JS Data API #572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions angular/angular-getting-started/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion angular/angular-getting-started/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@angular/platform-browser-dynamic": "^18.0.0",
"@angular/router": "^18.0.0",
"rxjs": "~7.8.0",
"talkjs": "^0.20.0",
"talkjs": "^0.36.0",
"tslib": "^2.3.0",
"zone.js": "~0.14.3"
},
Expand Down
6 changes: 3 additions & 3 deletions angular/angular-getting-started/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Component } from "@angular/core";
import { TalkjsChatComponent } from "./talkjs-chat/talkjs-chat.component";
import { ChatComponent } from "./chat/chat.component";

@Component({
selector: "app-root",
standalone: true,
imports: [TalkjsChatComponent],
template: ` <app-talkjs-chat></app-talkjs-chat> `,
imports: [ChatComponent],
template: ` <app-chat></app-chat> `,
styles: [],
})
export class AppComponent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,42 @@ import { Component } from "@angular/core";
import Talk from "talkjs";

@Component({
selector: "app-talkjs-chat",
selector: "app-chat",
standalone: true,
imports: [],
template: `
<div id="talkjs-container" style="height: 600px">Loading chats..</div>
`,
styles: ``,
})
export class TalkjsChatComponent {
export class ChatComponent {
constructor() {
Talk.ready.then(function () {
const me = new Talk.User({
id: "nina",
const session = new Talk.Session({
appId: "<APP_ID>",
userId: "nina",
});
session.currentUser.createIfNotExists({
name: "Nina",
email: "[email protected]",
photoUrl: "https://talkjs.com/new-web/avatar-7.jpg",
welcomeMessage: "Hi!",
});
const session = new Talk.Session({
appId: "<APP_ID>",
me: me,
});
const other = new Talk.User({
id: "frank",

const otherRef = session.user("frank");
otherRef.createIfNotExists({
name: "Frank",
email: "[email protected]",
photoUrl: "https://talkjs.com/new-web/avatar-8.jpg",
welcomeMessage: "Hey, how can I help?",
});

const conversation = session.getOrCreateConversation("new_conversation");
conversation.setParticipant(me);
conversation.setParticipant(other);
const conversationRef = session.conversation("new_conversation");
conversationRef.createIfNotExists();
conversationRef.participant(otherRef).createIfNotExists();

const chatbox = session.createChatbox();
chatbox.select(conversation);
chatbox.select(conversationRef);
chatbox.mount(document.getElementById("talkjs-container"));
});
}
Expand Down
19 changes: 11 additions & 8 deletions svelte/svelte/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@

onMount(async () => {
Talk.ready.then(() => {
const me = new Talk.User(oliver);
const other = new Talk.User(abby);
const session = new Talk.Session({
appId: appId,
userId: oliver.id,
});
session.currentUser.createIfNotExists(oliver);

const session = new Talk.Session({ appId, me });
const otherRef = session.user(abby.id);
otherRef.createIfNotExists(abby);

const conversationId = Talk.oneOnOneId(me, other);
const conversation = session.getOrCreateConversation(conversationId);
conversation.setParticipant(me);
conversation.setParticipant(other);
const conversationRef = session.conversation('svelte_example_conversation');
conversationRef.createIfNotExists();
conversationRef.participant(otherRef).createIfNotExists();

const chatbox = session.createChatbox();
chatbox.select(conversation);
chatbox.select(conversationRef);
chatbox.mount(element);
});
});
Expand Down
Loading