Skip to content

Commit

Permalink
add actioncable listening for real time events
Browse files Browse the repository at this point in the history
  • Loading branch information
schacon committed Oct 10, 2024
1 parent c14d7e6 commit 3a5d116
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"vite": "catalog:"
},
"dependencies": {
"@rails/actioncable": "^7.2.100",
"@sentry/sveltekit": "^8.9.2",
"highlight.js": "^11.10.0",
"marked": "^10.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
import DiffPatch from '$lib/components/DiffPatch.svelte';
import DiffPatchArray from '$lib/components/DiffPatchArray.svelte';
import { createConsumer } from '@rails/actioncable';
import { marked } from 'marked';
import { onMount } from 'svelte';
import Gravatar from 'svelte-gravatar';

Check failure on line 7 in apps/web/src/routes/projects/[projectId]/branches/[branchId]/stack/[changeId]/+page.svelte

View workflow job for this annotation

GitHub Actions / lint-node

Unable to resolve path to module 'svelte-gravatar'
Expand All @@ -13,12 +14,15 @@
let events: any = [];
let key: any = '';
let uuid: any = '';
let consumer;
export let data: any;
onMount(() => {
key = localStorage.getItem('gb_access_token');
listenToChat(key);
let projectId = data.projectId;
let branchId = data.branchId;
let changeId = data.changeId;
Expand Down Expand Up @@ -46,6 +50,21 @@
}
});
function listenToChat(token: string) {
// connect to actioncable to subscribe to chat events
let wsHost = env.PUBLIC_APP_HOST.replace('http', 'ws') + 'cable';
consumer = createConsumer(wsHost + '?token=' + token);
consumer.subscriptions.create(
{ channel: 'ChatChannel', change_id: data.changeId, project_id: data.projectId },
{
received(data: any) {
// todo: update chat window with new message
console.log('received', data);
}
}
);
}
function scrollToBottom() {
let chatWindow = document.querySelector<HTMLElement>('.chatWindow');
if (chatWindow) {
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

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

0 comments on commit 3a5d116

Please sign in to comment.