Skip to content
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

Ably-js v2 migration #10

Merged
merged 5 commits into from
May 29, 2024
Merged
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
449 changes: 46 additions & 403 deletions README.md

Large diffs are not rendered by default.

14 changes: 10 additions & 4 deletions app/api/route.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import Ably from 'ably/promises';
import Ably from 'ably';

export async function GET(request) {
const client = new Ably.Realtime(process.env.ABLY_API_KEY);
const tokenRequestData = await client.auth.createTokenRequest({ clientId: 'ably-nextjs-demo' });
// ensure Vercel doesn't cache the result of this route,
// as otherwise the token request data will eventually become outdated
// and we won't be able to authenticate on client side
export const revalidate = 0;

export async function GET(request) {
const client = new Ably.Rest(process.env.ABLY_API_KEY);
const tokenRequestData = await client.auth.createTokenRequest({
clientId: 'ably-nextjs-demo',
});
console.log(`Request: ${JSON.stringify(tokenRequestData)}`);
return Response.json(tokenRequestData);
}
2 changes: 1 addition & 1 deletion app/layout.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import './global.css';
import './globals.css';

export const metadata = {
title: 'Next.js',
Expand Down
8 changes: 5 additions & 3 deletions components/Chat.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
'use client';

import * as Ably from 'ably';
import { AblyProvider } from 'ably/react';
import { AblyProvider, ChannelProvider } from 'ably/react';
import ChatBox from './ChatBox.jsx';

export default function Chat() {
const client = Ably.Realtime.Promise({ authUrl: '/api' });
const client = new Ably.Realtime({ authUrl: '/api' });

return (
<AblyProvider client={client}>
<ChatBox />
<ChannelProvider channelName="chat-demo">
<ChatBox />
</ChannelProvider>
</AblyProvider>
);
}
2 changes: 0 additions & 2 deletions components/ChatBox.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use client';

import React, { useEffect, useState } from 'react';
import { useChannel } from 'ably/react';
import styles from './ChatBox.module.css';
Expand Down
8 changes: 8 additions & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
serverComponentsExternalPackages: ['ably'],
},
};

export default nextConfig;
147 changes: 73 additions & 74 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"format:check": "prettier --check --ignore-path .gitignore app components"
},
"dependencies": {
"ably": "^1.2.44",
"next": "^13.4.19",
"ably": "^2.0.4",
"next": "^14.2.3",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
Expand Down
Loading