Skip to content

Commit

Permalink
Merge pull request #10 from ably-labs/ably-js-v2-migration
Browse files Browse the repository at this point in the history
Ably-js v2 migration
  • Loading branch information
VeskeR authored May 29, 2024
2 parents a03599a + d0b0f00 commit 7e17fa2
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 489 deletions.
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

0 comments on commit 7e17fa2

Please sign in to comment.