-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from ably-labs/ably-js-v2-migration
Ably-js v2 migration
- Loading branch information
Showing
8 changed files
with
145 additions
and
489 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters