├── .eslintrc.json ├── .github ├── dependabot.yml └── workflows │ ├── create-infra.yml.disabled │ └── linkchecker.yml ├── .gitignore ├── .lycheeignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── app ├── authentication │ ├── authentication-client.tsx │ └── page.tsx ├── global.css ├── history │ ├── history-client.tsx │ └── page.tsx ├── layout.tsx ├── page.tsx ├── presence │ ├── page.tsx │ └── presence-client.tsx ├── pub-sub │ ├── page.tsx │ └── pubsub-client.tsx ├── publish │ └── route.ts └── token │ └── route.ts ├── components ├── FooterItem.tsx ├── MenuItem.tsx ├── SampleHeader.tsx ├── Sidebar.tsx ├── SocialItem.tsx └── logger.tsx ├── media └── ably-nextjs.png ├── next.config.js ├── package-lock.json ├── package.json ├── postcss.config.js ├── public ├── ably-logo-col-horiz-rgb.png ├── ably-logo-col-horiz-rgb.svg ├── ably-logo-col-inv-horiz-rgb.svg ├── ably-motif-col-rgb.svg ├── assets │ ├── AblyLogo.svg │ ├── AblyLogoWithText.svg │ ├── Alert.svg │ ├── ArrowRight.svg │ ├── Authentication.svg │ ├── DiscordLogo.svg │ ├── ExploreNow.svg │ ├── GithubLogo.svg │ ├── GreenButton.svg │ ├── History.svg │ ├── HorizontalRule.svg │ ├── LinkedInLogo.svg │ ├── NextjsLogo.svg │ ├── PlusSign.svg │ ├── Presence.svg │ ├── PubSubChannels.svg │ ├── RedButton.svg │ ├── XTwitterLogo.svg │ ├── YellowButton.svg │ ├── icon-social-discord-col.svg │ ├── icon-social-github-col.svg │ ├── icon-social-linkedin-col.svg │ └── icon-social-x-col.svg └── vercel.svg ├── random-names-generator.d.ts ├── tailwind.config.js ├── tsconfig.json └── vercel.json /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "next/core-web-vitals", 3 | "plugins": [ 4 | "react-hooks" 5 | ], 6 | "rules": { 7 | "react-hooks/rules-of-hooks": "error", 8 | "react-hooks/exhaustive-deps": "warn" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | 4 | - package-ecosystem: "github-actions" 5 | directory: "/" 6 | schedule: 7 | interval: "daily" 8 | -------------------------------------------------------------------------------- /.github/workflows/create-infra.yml.disabled: -------------------------------------------------------------------------------- 1 | name: Create Infrastructure 2 | 3 | on: 4 | push: 5 | paths: 6 | - '.github/workflows/create-infra.yml' 7 | workflow_dispatch: 8 | 9 | jobs: 10 | create_infra: 11 | runs-on: ubuntu-latest 12 | name: Create Ably App 13 | steps: 14 | - name: Create Ably App 15 | id: ablyapp 16 | uses: ably-labs/ably-control-api-action@v0.1.5 17 | with: 18 | account-id: '${{ secrets.ABLY_ACCOUNT_ID }}' 19 | control-api-key: '${{ secrets.ABLY_CONTROL_API_KEY }}' -------------------------------------------------------------------------------- /.github/workflows/linkchecker.yml: -------------------------------------------------------------------------------- 1 | name: Link Checker 2 | 3 | on: 4 | schedule: 5 | - cron: "0 5 * * *" 6 | pull_request: 7 | types: [opened, edited, synchronize, reopened] 8 | workflow_dispatch: 9 | 10 | permissions: 11 | contents: read 12 | pull-requests: write 13 | 14 | jobs: 15 | link-checker: 16 | runs-on: ubuntu-latest 17 | steps: 18 | - name: 'Checkout source code' 19 | uses: actions/checkout@v3 20 | 21 | - name: Link Checker 22 | id: lychee 23 | uses: lycheeverse/lychee-action@v1.5.4 24 | with: 25 | fail: true 26 | args: --verbose --no-progress --exclude-mail --exclude-loopback **/*.md 27 | env: 28 | GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # next.js 12 | /.next/ 13 | /out/ 14 | 15 | # production 16 | /build 17 | 18 | # misc 19 | .DS_Store 20 | *.pem 21 | 22 | # debug 23 | npm-debug.log* 24 | yarn-debug.log* 25 | yarn-error.log* 26 | .pnpm-debug.log* 27 | 28 | # local env files 29 | .env*.local 30 | 31 | # vercel 32 | .vercel 33 | 34 | # typescript 35 | *.tsbuildinfo 36 | next-env.d.ts 37 | -------------------------------------------------------------------------------- /.lycheeignore: -------------------------------------------------------------------------------- 1 | https://github.com/ably-labs/static-assets -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Ably Community Code of Conduct 2 | 3 | We, at Ably, value every member’s participation in our community and want to make everyone feel welcome. We have this Code of Conduct to outline what is expected from our community members and expect all members to respect and follow it. 4 | 5 | This Code of Conduct has the following parts: Our Pledge, Our Standards, Enforcement and Attributions. 6 | 7 | ## Our Pledge 8 | 9 | We as community leaders, members, contributors, event attendees, speakers, sponsors and partners pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. 10 | 11 | ## Our Standards 12 | 13 | Examples of behaviour that contribute to a positive environment for our community include: 14 | 15 | - Demonstrating empathy and kindness towards other people 16 | - Being respectful of differing opinions, viewpoints, and experiences 17 | - Giving and gracefully accepting constructive feedback 18 | - Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience 19 | - Focusing on what is best not just for us as individuals, but for the overall community 20 | 21 | Examples of unacceptable behaviour include: 22 | 23 | - The use of sexualized language or imagery, and sexual attention or advances of any kind 24 | - Trolling, insulting or derogatory comments, and personal or political attacks 25 | - Public or private harassment 26 | - Publishing other's private information, such as a physical or email address or other identifying information, without their explicit permission 27 | - Other conduct which could reasonably be considered inappropriate in a professional setting, this isn’t an exhaustive list 28 | 29 | 30 | ## Enforcement 31 | 32 | Community leaders are responsible for clarifying and enforcing our standards of acceptable behaviour and will take appropriate and fair corrective action in response to any behaviour that they deem inappropriate, threatening, offensive, or harmful. 33 | 34 | Community leaders have the right and responsibility to remove, edit, or reject comments, messages, commits, questions and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. 35 | 36 | ## Scope 37 | 38 | This Code of Conduct applies within all community spaces and also applies when an individual is officially representing the community in public spaces. Examples of community spaces include physical and virtual events that we organise or participate in irrespective of platform or venue, in online social spaces for example Discord and in broadcasting platforms such as Twitch. 39 | 40 | ## Enforcement Guidelines 41 | 42 | If you witness or are subject to instances of abusive, harassing, or otherwise unacceptable behaviour, it should be reported to the community leaders responsible for enforcement at [devrel@ably.com](mailto:devrel@ably.com). All complaints will be reviewed and investigated promptly and fairly, with communication being provided on progress and outcome. If a report is being made about a team member of Ably DevRel, the reporter can instead email [jo.franchetti@ably.com](mailto:Jo.franchetti@ably.com) or [beth.loft@ably.com](mailto:beth.loft@ably.com). 43 | 44 | All community leaders are obligated to respect the privacy and security of the reporter of any incident. 45 | 46 | Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct. 47 | 48 | ### 1. Simple Warning Issued 49 | 50 | **Behaviour:** 51 | 52 | Unprofessional or unwelcome behaviour in the community including the use of inappropriate language or other unacceptable comments. 53 | 54 | **Consequence:** 55 | 56 | A private, written warning from community leaders, with clarity of violation, explanation of why the behaviour is inappropriate and consequences of continued behaviour. Additionally: 57 | 58 | Any member who is asked to stop such behaviour is expected to comply immediately. 59 | 60 | 61 | ### 2. Warning 62 | 63 | **Behaviour:** 64 | 65 | A violation through a single incident or series of actions. 66 | 67 | **Consequence:** 68 | 69 | A private, written warning from community leaders, with clarity of violation, explanation of why the behaviour is inappropriate and consequences of continued behaviour. Additionally: 70 | 71 | A specified time period of strictly no unsolicited interaction with those involved in the report - including community leaders handling the enforcement of the code of conduct - across platforms and spaces, publicly or privately. 72 | 73 | A requirement to read and reconfirm agreement to follow the code of conduct. 74 | 75 | ### 3. Temporary Ban 76 | 77 | **Behaviour:** 78 | 79 | A serious violation of community standards, including sustained inappropriate behaviour. 80 | 81 | **Consequence:** 82 | 83 | A private, written warning from community leaders, with clarity of violation, explanation of why the behaviour is inappropriate and consequences of continued behaviour. Additionally: 84 | 85 | A temporary ban for an appropriate and specified period of time from any interaction, unsolicited or otherwise with the community - including community leaders handling the enforcement of the code of conduct - across platforms and spaces during this period. 86 | 87 | 88 | 89 | ### 4. Permanent Ban 90 | 91 | **Behaviour:** 92 | 93 | A pattern of violations of community standards, including sustained inappropriate behaviour, harassment of an individual, or aggression toward or disparagement of classes of individuals. 94 | 95 | **Consequence:** 96 | 97 | A private, written warning from community leaders, with clarity of violation, explanation of why the behaviour was inappropriate and consequences of continued behaviour. Additionally: 98 | 99 | A permanent ban from any sort of public interaction within the community. 100 | 101 | ## Attributions 102 | 103 | This Code of Conduct’s pledge, standards and enforcement are adapted from the [Contributor Covenant](https://www.contributor-covenant.org/), V2.1, available at [Contributor Covenant](https://www.contributor-covenant.org/version/2/1/code_of_conduct/). (For answers to common questions about this code of conduct, see the FAQ at [Contributor Covenant: Frequently Asked Questions about Contributor Covenant](https://www.contributor-covenant.org/faq). Translations are available at [Contributor Covenant: Contributor Covenant Translations](https://www.contributor-covenant.org/translations).) 104 | 105 | The Community Enforcement Guidelines are adapted from [Mozilla’s code of conduct consequence ladder](https://github.com/mozilla/inclusion/blob/master/code-of-conduct-enforcement/consequence-ladder.md). 106 | 107 | ## Questions? 108 | 109 | If you have questions about our code of conduct, please feel free to [contact us](mailto:devrel@ably.com). 110 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Welcome to the contributing guide 2 | 3 | Thank you for investing your time in contributing to our project! :sparkles: 4 | 5 | Read our [Code of Conduct](./CODE_OF_CONDUCT.md) to keep our community approachable and respectable. 6 | 7 | In this guide you will get an overview of the contribution workflow from opening an issue, creating a PR, reviewing, and merging the PR. 8 | 9 | ## New contributor guide 10 | 11 | To get an overview of the project, read the [README](README.md). Here are some resources to help you get started with open source contributions: 12 | 13 | - [Finding ways to contribute to open source on GitHub](https://docs.github.com/en/get-started/exploring-projects-on-github/finding-ways-to-contribute-to-open-source-on-github) 14 | - [Set up Git](https://docs.github.com/en/get-started/quickstart/set-up-git) 15 | - [GitHub flow](https://docs.github.com/en/get-started/quickstart/github-flow) 16 | - [Collaborating with pull requests](https://docs.github.com/en/github/collaborating-with-pull-requests) 17 | 18 | ## Getting started 19 | 20 | If you would like to add a new feature please submit an issue first that describes the feature in detail. Once there is agreement on the new feature you can continue and submit a pull request. 21 | 22 | ### Issues 23 | 24 | #### Create a new issue 25 | 26 | If you spot a problem, [search if an issue already exists](https://github.com/ably-labs/ably-nextjs-fundamentals-kit/issues). If a related issue doesn't exist, you can open a [new issue](https://github.com/ably-labs/ably-nextjs-fundamentals-kit/issues/new). 27 | 28 | #### Solve an issue 29 | 30 | Scan through our [existing issues](https://github.com/ably-labs/ably-nextjs-fundamentals-kit/issues) to find one that interests you. As a general rule, we don’t assign issues to anyone. If you find an issue to work on, you are welcome to open a PR with a fix. 31 | 32 | #### Make changes locally 33 | 34 | 1. [Install Git](https://docs.github.com/en/get-started/quickstart/set-up-git#setting-up-git). 35 | 36 | 2. Fork the repository. 37 | 38 | - Using GitHub Desktop: 39 | - [Getting started with GitHub Desktop](https://docs.github.com/en/desktop/installing-and-configuring-github-desktop/getting-started-with-github-desktop) will guide you through setting up Desktop. 40 | - Once Desktop is set up, you can use it to [fork the repo](https://docs.github.com/en/desktop/contributing-and-collaborating-using-github-desktop/cloning-and-forking-repositories-from-github-desktop)! 41 | 42 | - Using the command line: 43 | - [Fork the repo](https://docs.github.com/en/github/getting-started-with-github/fork-a-repo#fork-an-example-repository) so that you can make your changes without affecting the original project until you're ready to merge them. 44 | 45 | - GitHub Codespaces: 46 | - [Fork, edit, and preview](https://docs.github.com/en/free-pro-team@latest/github/developing-online-with-codespaces/creating-a-codespace) using [GitHub Codespaces](https://github.com/features/codespaces) without having to install and run the project locally. 47 | 48 | 3. Create a working branch and start with your changes! 49 | 50 | ### Commit your update 51 | 52 | Commit the changes once you are happy with them. See [Atom's contributing guide](https://github.com/atom/atom/blob/master/CONTRIBUTING.md#git-commit-messages) to know how to use emoji for commit messages. 53 | 54 | ### Pull Request 55 | 56 | When you're finished with the changes, create a pull request, also known as a PR. 57 | 58 | - Fill the "Ready for review" template so that we can review your PR. This template helps reviewers understand your changes as well as the purpose of your pull request. 59 | - Don't forget to [link PR to issue](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue) if you are solving one. 60 | - Enable the checkbox to [allow maintainer edits](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/allowing-changes-to-a-pull-request-branch-created-from-a-fork) so the branch can be updated for a merge. 61 | Once you submit your PR, a Docs team member will review your proposal. We may ask questions or request for additional information. 62 | - We may ask for changes to be made before a PR can be merged, either using [suggested changes](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/incorporating-feedback-in-your-pull-request) or pull request comments. You can apply suggested changes directly through the UI. You can make any other changes in your fork, then commit them to your branch. 63 | - As you update your PR and apply changes, mark each conversation as [resolved](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/commenting-on-a-pull-request#resolving-conversations). 64 | - If you run into any merge issues, checkout this [git tutorial](https://githubtraining.github.io/training-manual/#/12b_resolving_merge_conflicts) to help you resolve merge conflicts and other issues. 65 | 66 | ### Your PR is merged! 67 | 68 | Congratulations :tada::tada: The Ably Labs team thanks you! :sparkles: 69 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ably serverless WebSockets and Next.js fundamentals starter kit 2 | 3 | ![Ably serverless WebSockets and Next.js fundamentals starter kit demo](media/ably-nextjs.png) 4 | 5 | ## Description 6 | 7 | This [Ably](https://ably.com?utm_source=github&utm_medium=github-repo&utm_campaign=GLB-2211-ably-nextjs-fundamentals-kit&utm_content=ably-nextjs-fundamentals-kit&src=GLB-2211-ably-nextjs-fundamentals-kit-github-repo) and [Next.js](https://nextjs.org) fundamentals starter kit demonstrates using some of the Ably's core functionality with Next.js. You can build features and use cases upon these fundamentals such as notifications, activity streams, chat, realtime visualisations and dashboards, and collaborative multiplayer experiences. 8 | 9 | The Ably fundamentals demonstrated within this repo are: 10 | 11 | - [Token Authentication](https://ably.com/docs/realtime/authentication?utm_source=github&utm_medium=github-repo&utm_campaign=GLB-2211-ably-nextjs-fundamentals-kit&utm_content=ably-nextjs-fundamentals-kit&src=GLB-2211-ably-nextjs-fundamentals-kit-github-repo#token-authentication) - authenticate and establish a persistent bi-direction connection to the Ably platform. 12 | - [Pub/Sub (Publish/Subscribe)](https://ably.com/docs/realtime/channels?utm_source=github&utm_medium=github-repo&utm_campaign=GLB-2211-ably-nextjs-fundamentals-kit&utm_content=ably-nextjs-fundamentals-kit&src=GLB-2211-ably-nextjs-fundamentals-kit-github-repo) - publish messages on channels and subscribe to channels to receive messages. 13 | - [Presence](https://ably.com/docs/realtime/presence?utm_source=github&utm_medium=github-repo&utm_campaign=GLB-2211-ably-nextjs-fundamentals-kit&utm_content=ably-nextjs-fundamentals-kit&src=GLB-2211-ably-nextjs-fundamentals-kit-github-repo) - keep track of devices that are present on a channel. This is great for tracking if a device is online or offline or indicating if a user is in a chat room when using Ably for Chat. 14 | - [History](https://ably.com/docs/realtime/history?utm_source=github&utm_medium=github-repo&utm_campaign=GLB-2211-ably-nextjs-fundamentals-kit&utm_content=ably-nextjs-fundamentals-kit&src=GLB-2211-ably-nextjs-fundamentals-kit-github-repo) - Retrieve a history of messages that have been published to a channel. 15 | 16 | The project uses the following components: 17 | 18 | - [Next.js](https://nextjs.org), a flexible React framework that gives you building blocks to create fast web applications. 19 | - [Ably](https://ably.com?utm_source=github&utm_medium=github-repo&utm_campaign=GLB-2211-ably-nextjs-fundamentals-kit&utm_content=ably-nextjs-fundamentals-kit&src=GLB-2211-ably-nextjs-fundamentals-kit-github-repo), for realtime messaging at scale. 20 | 21 | ## Building & running locally 22 | 23 | ### Prerequisites 24 | 25 | 1. [Sign up](https://ably.com/signup?utm_source=github&utm_medium=github-repo&utm_campaign=GLB-2211-ably-nextjs-fundamentals-kit&utm_content=ably-nextjs-fundamentals-kit&src=GLB-2211-ably-nextjs-fundamentals-kit-github-repo) or [log in](https://ably.com/login?utm_source=github&utm_medium=github-repo&utm_campaign=GLB-2211-ably-nextjs-fundamentals-kit&utm_content=ably-nextjs-fundamentals-kit&src=GLB-2211-ably-nextjs-fundamentals-kit-github-repo) to ably.com, and [create a new app and copy the API key](https://faqs.ably.com/setting-up-and-managing-api-keys?utm_source=github&utm_medium=github-repo&utm_campaign=GLB-2211-ably-nextjs-fundamentals-kit&utm_content=ably-nextjs-fundamentals-kit&src=GLB-2211-ably-nextjs-fundamentals-kit-github-repo). 26 | 2. To deploy to [Vercel](https://vercel.com), create a Vercel account. 27 | 28 | ### Configure the app 29 | 30 | Create a `.env.local` file with your Ably API key: 31 | 32 | ```bash 33 | echo "ABLY_API_KEY={YOUR_ABLY_API_KEY_HERE}">.env 34 | ``` 35 | 36 | ### Run the Next.js app 37 | 38 | ```bash 39 | npm run dev 40 | # or 41 | yarn dev 42 | ``` 43 | 44 | ## Deploy on Vercel 45 | 46 | The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. 47 | 48 | [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fably-labs%2Fably-nextjs-fundamentals-kit&env=ABLY_API_KEY) 49 | 50 | ## Contributing 51 | 52 | Want to help contributing to this project? Have a look at our [contributing guide](CONTRIBUTING.md)! 53 | 54 | ## More info 55 | 56 | - [Join the Ably Discord server](https://discord.gg/q89gDHZcBK) 57 | - [Follow Ably on Twitter](https://twitter.com/ablyrealtime) 58 | - [Use the Ably SDKs](https://github.com/ably/) 59 | - [Visit the Ably website](https://ably.com?utm_source=github&utm_medium=github-repo&utm_campaign=GLB-2211-ably-nextjs-fundamentals-kit&utm_content=ably-nextjs-fundamentals-kit&src=GLB-2211-ably-nextjs-fundamentals-kit-github-repo) 60 | 61 | --- 62 | [![Ably logo](https://static.ably.dev/badge-black.svg?ably-nextjs-fundamentals-kit-github-repo)](https://ably.com?utm_source=github&utm_medium=github-repo&utm_campaign=GLB-2211-ably-nextjs-fundamentals-kit&utm_content=ably-nextjs-fundamentals-kit&src=GLB-2211-ably-nextjs-fundamentals-kit-github-repo) -------------------------------------------------------------------------------- /app/authentication/authentication-client.tsx: -------------------------------------------------------------------------------- 1 | 2 | 'use client' 3 | 4 | import { MouseEventHandler, MouseEvent, useState } from 'react' 5 | 6 | import * as Ably from 'ably' 7 | import Logger, { LogEntry } from '../../components/logger' 8 | import SampleHeader from '../../components/SampleHeader' 9 | import { AblyProvider, useAbly, useConnectionStateListener } from 'ably/react' 10 | 11 | export default function Authentication() { 12 | 13 | const client = new Ably.Realtime({ authUrl: '/token', authMethod: 'POST' }); 14 | 15 | return ( 16 | 17 |
18 |
19 | 20 |
21 | Authenticate and establish a persistant bi-directional connection to the Ably platform. 22 |
23 | 24 |
25 |
26 |
27 | ) 28 | } 29 | 30 | const ConnectionStatus = () => { 31 | 32 | const ably = useAbly(); 33 | 34 | const [logs, setLogs] = useState>([]) 35 | const [connectionState, setConnectionState] = useState('unknown') 36 | 37 | useConnectionStateListener((stateChange) => { 38 | setConnectionState(stateChange.current) 39 | setLogs(prev => [...prev, new LogEntry(`Connection state change: ${stateChange.previous} -> ${stateChange.current}`)]) 40 | }) 41 | 42 | const connectionToggle: MouseEventHandler = (_event: MouseEvent) => { 43 | if(connectionState === 'connected') { 44 | ably.connection.close() 45 | } 46 | else if(connectionState === 'closed') { 47 | ably.connection.connect() 48 | } 49 | } 50 | 51 | return ( 52 | <> 53 |
54 |
55 |
56 | connection status 57 |   58 | =  59 | 60 | {connectionState} 61 | 62 |
63 |
64 |
65 |
66 | 67 |
68 |
69 |
70 | 71 | 72 | ) 73 | } -------------------------------------------------------------------------------- /app/authentication/page.tsx: -------------------------------------------------------------------------------- 1 | /** 2 | * Warning: Opening too many live preview tabs will slow down performance. 3 | * We recommend closing them after you're done. 4 | */ 5 | import React from "react"; 6 | import "../global.css"; 7 | import dynamic from 'next/dynamic'; 8 | import Sidebar from "../../components/Sidebar.tsx"; 9 | 10 | const AuthenticationClient = dynamic(() => import('./authentication-client.tsx'), { 11 | ssr: false, 12 | }) 13 | 14 | const Authentication = () => { 15 | 16 | const pageId = "Authentication"; 17 | 18 | return ( 19 | <> 20 | 21 |
22 | 23 |
24 | 25 | ) 26 | }; 27 | 28 | export default Authentication; 29 | -------------------------------------------------------------------------------- /app/global.css: -------------------------------------------------------------------------------- 1 | @import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@500&family=Manrope:wght@400;700&display=swap'); 2 | @tailwind base; 3 | @tailwind components; 4 | @tailwind utilities; -------------------------------------------------------------------------------- /app/history/history-client.tsx: -------------------------------------------------------------------------------- 1 | 'use client' 2 | 3 | import * as Ably from 'ably'; 4 | 5 | import { AblyProvider, ChannelProvider, useChannel } from "ably/react" 6 | import { useState, useEffect } from 'react' 7 | import Logger, { LogEntry } from '../../components/logger'; 8 | import SampleHeader from '../../components/SampleHeader'; 9 | 10 | export default function Presence() { 11 | 12 | const client = new Ably.Realtime ({ authUrl:'/token', authMethod: 'POST' }); 13 | 14 | return ( 15 | 16 | 17 |
18 |
19 |
20 | 21 |
22 | Retrieve a history of messages that have been published to a channel. 23 | Messages are only stored for 2 minutes by default. In order for them 24 | to be stored for longer you should enable the  25 | 26 | Persist all messages 27 |   28 | channel rule 29 |  for 30 | the  31 | 32 | status-updates 33 | 34 |  channel in your Ably app   35 |
36 |
37 |
38 |
39 | Alert 40 |
41 |
42 | Important: You need to 43 | publish at least 1 message from the  44 | 45 | Pub/Sub Channels example 46 | 47 |  to see history log. 48 |
49 | 50 |
51 | 52 |
53 |
54 |
55 |
56 | ) 57 | } 58 | 59 | function HistoryMessages() { 60 | 61 | const [realtimeLogs, setRealtimeLogs] = useState>([]) 62 | const [historicalLogs, setHistoricalLogs] = useState>([]) 63 | 64 | const { channel } = useChannel("status-updates", (message: Ably.Message) => { 65 | console.log(message); 66 | setRealtimeLogs(prev => [...prev, new LogEntry(`✉️ event name: ${message.name} text: ${message.data.text}`)]) 67 | }); 68 | 69 | useEffect(() => { 70 | const getHistory = async () => { 71 | let history: Ably.PaginatedResult | null = await channel.history() 72 | do { 73 | history.items.forEach(message => { 74 | setHistoricalLogs(prev => [ 75 | ...prev, 76 | new LogEntry(`"${message.data.text}" sent at ${new Date(message.timestamp!).toISOString()}`) 77 | ]) 78 | }) 79 | history = await history.next() 80 | } 81 | while(history) 82 | } 83 | getHistory() 84 | }, []) 85 | 86 | return ( 87 | <> 88 |
89 |
90 | history 91 |
92 | { 93 | historicalLogs.length > 0? ( 94 | 95 | ) : ( 96 |
97 |
98 |

No historical messages found

99 |
100 |
101 | )} 102 | 103 |
104 |
105 |
106 | realtime 107 |
108 | { 109 | realtimeLogs.length > 0? ( 110 | 111 | ) : ( 112 |
113 |
114 |

No realtime messages received yet

115 |
116 |
117 | )} 118 |
119 | 120 | //
121 | //
122 | //

History

123 | // { 124 | // historicalLogs.length > 0? 125 | // 126 | // : 127 | //

No historical messages found

128 | // } 129 | //
130 | //
131 | //

Realtime

132 | // { 133 | // realtimeLogs.length > 0? 134 | // 135 | // : 136 | //

No realtime messages received yet

137 | // } 138 | //
139 | //
140 | ) 141 | } 142 | -------------------------------------------------------------------------------- /app/history/page.tsx: -------------------------------------------------------------------------------- 1 | /** 2 | * Warning: Opening too many live preview tabs will slow down performance. 3 | * We recommend closing them after you're done. 4 | */ 5 | import React from "react"; 6 | import "../global.css"; 7 | import dynamic from 'next/dynamic'; 8 | import MenuFooter from "../../components/FooterItem.tsx"; 9 | import MenuItem from "../../components/MenuItem.tsx"; 10 | import Sidebar from "../../components/Sidebar.tsx"; 11 | 12 | const HistoryClient = dynamic(() => import('./history-client.tsx'), { 13 | ssr: false, 14 | }) 15 | 16 | const History = () => { 17 | 18 | const pageId = "History" 19 | 20 | return ( 21 | <> 22 | 23 |
24 | 25 |
26 | 27 | ) 28 | } 29 | 30 | export default History; 31 | -------------------------------------------------------------------------------- /app/layout.tsx: -------------------------------------------------------------------------------- 1 | import './global.css' 2 | import type { Metadata } from 'next' 3 | 4 | export const metadata: Metadata = { 5 | title: 'Ably & Next.js fundamentals kit', 6 | description: 'Generated by create next app', 7 | } 8 | 9 | export default function RootLayout({ 10 | children, 11 | }: { 12 | children: React.ReactNode 13 | }) { 14 | return ( 15 | 16 | 17 |
18 |
19 | {children} 20 |
21 |
22 | 23 | 24 | ) 25 | } -------------------------------------------------------------------------------- /app/page.tsx: -------------------------------------------------------------------------------- 1 | /** 2 | * Warning: Opening too many live preview tabs will slow down performance. 3 | * We recommend closing them after you're done. 4 | */ 5 | import React from "react"; 6 | import "./global.css"; 7 | import Sidebar from "../components/Sidebar"; 8 | 9 | const Home = () => { 10 | 11 | const pageId = "Start"; 12 | 13 | return ( 14 | <> 15 | 16 |
17 |
18 |
19 |
20 | AblyLogo 26 |
27 | plus 33 |
34 | Next.js 40 |
41 |
42 | 43 | At Ably we are big fans of Next.js  44 | 45 | / This application demonstrates using some of the Ably fundamentals 46 | with Next.js. You can build features and use cases upon these 47 | fundamentals such as notifications, activity streams, chat, realtime 48 | visualisations and dashboards, and collaborative multiplayer 49 | experiences. 50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 | Authentication 64 |
65 |
66 |
67 | Authentication 68 |
69 |
70 |
71 |
72 | Token Authentication is the recommended approach for auth 73 | with Ably. 74 |
75 |
76 | 93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 | Pub/Sub Channels 107 |
108 |
109 |
110 | Pub/Sub Channels 111 |
112 |
113 |
114 |
115 | Pub/Sub (Publish/Subscribe) with Ably lets you publish 116 | messages on channels and subscribe to channels to receive 117 | messages. 118 |
119 | 136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 | Presence 152 |
153 |
154 |
155 | Presence 156 |
157 |
158 |
159 |
160 | Presence with Ably allows you to keep track of devices that 161 | are present on a channel. This is great for tracking if a 162 | device is online or offline or indicating if a user is in a 163 | chat room when using Ably for Chat. 164 |
165 | 181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 | History 195 |
196 |
197 |
198 | History 199 |
200 |
201 |
202 |
203 | Retrieve a history of messages that have been published to a 204 | channel. 205 |
206 | 222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 | 231 | ) 232 | } 233 | ; 234 | 235 | export default Home; 236 | -------------------------------------------------------------------------------- /app/presence/page.tsx: -------------------------------------------------------------------------------- 1 | /** 2 | * Warning: Opening too many live preview tabs will slow down performance. 3 | * We recommend closing them after you're done. 4 | */ 5 | import React from "react"; 6 | import "../global.css"; 7 | import dynamic from 'next/dynamic'; 8 | import MenuFooter from "../../components/FooterItem.tsx"; 9 | import MenuItem from "../../components/MenuItem.tsx"; 10 | import Sidebar from "../../components/Sidebar.tsx"; 11 | 12 | const PresenceClient = dynamic(() => import('./presence-client.tsx'), { 13 | ssr: false, 14 | }) 15 | 16 | const Presence = () => { 17 | 18 | const pageId = "Presence" 19 | 20 | return ( 21 | <> 22 | 23 |
24 | 25 |
26 | 27 | ) 28 | } 29 | 30 | export default Presence; 31 | -------------------------------------------------------------------------------- /app/presence/presence-client.tsx: -------------------------------------------------------------------------------- 1 | 'use client' 2 | 3 | import * as Ably from 'ably'; 4 | import names from 'random-names-generator' 5 | 6 | import { AblyProvider, ChannelProvider, useAbly, usePresence, usePresenceListener } from "ably/react" 7 | import { useState, ReactElement, FC } from 'react' 8 | import Logger, { LogEntry } from '../../components/logger'; 9 | import SampleHeader from '../../components/SampleHeader'; 10 | 11 | export default function Presence() { 12 | 13 | const [randomName] = useState(names.random()); 14 | const [isOnline, setIsOnline] = useState(false) 15 | 16 | const client = new Ably.Realtime ({ authUrl:'/token', authMethod: 'POST', clientId: randomName }); 17 | 18 | function toggleState(val: boolean) { 19 | setIsOnline(val) 20 | } 21 | 22 | return ( 23 | 24 | 25 |
26 |
27 | 28 |
29 | Presence with Ably allows you to keep track of devices that are 30 | present on a channel. This is great for tracking if a device is 31 | online or offline or indicating if a user is in a chat room when 32 | using Ably for Chat.  33 | 34 | Open this page in another tab 35 | 36 |  to see more users enter and leave the presence channel. 37 |
38 | { isOnline ? ( 39 | 40 | ) : ( 41 |
42 |
43 | 44 |
45 |
46 | ) } 47 |
48 |
49 |
50 |
51 | ) 52 | } 53 | 54 | const PresenceMessages: FC = ({toggle}): ReactElement => { 55 | 56 | const [logs, setLogs] = useState>([]) 57 | const client = useAbly(); 58 | 59 | const { updateStatus } = usePresence("room", {'status':'available'}, ); 60 | const { presenceData } = usePresenceListener("room", (member) => { 61 | setLogs(prev => [...prev, new LogEntry(`action: ${member.action} clientId: ${member.clientId}`)]) 62 | }); 63 | 64 | return ( 65 | <> 66 |
67 |
68 |
69 |
    70 | {presenceData.map((member) => { 71 | return (
  • {member.clientId}
  • ) 72 | })} 73 |
74 |
75 |
76 |
77 |
78 | 79 |
80 |
81 |
82 | 83 | 84 | ) 85 | } 86 | -------------------------------------------------------------------------------- /app/pub-sub/page.tsx: -------------------------------------------------------------------------------- 1 | /** 2 | * Warning: Opening too many live preview tabs will slow down performance. 3 | * We recommend closing them after you're done. 4 | */ 5 | import React from "react"; 6 | import "../global.css"; 7 | import dynamic from 'next/dynamic'; 8 | import Sidebar from "../../components/Sidebar.tsx"; 9 | 10 | const PubSubClient = dynamic(() => import('./pubsub-client.tsx'), { 11 | ssr: false, 12 | }) 13 | 14 | const PubSub = () => { 15 | 16 | const pageId="PubSubChannels" 17 | 18 | return ( 19 | <> 20 | 21 |
22 | 23 |
24 | 25 | ) 26 | } 27 | 28 | export default PubSub; 29 | -------------------------------------------------------------------------------- /app/pub-sub/pubsub-client.tsx: -------------------------------------------------------------------------------- 1 | 'use client' 2 | 3 | import * as Ably from 'ably'; 4 | import { AblyProvider, ChannelProvider, useChannel } from "ably/react" 5 | import { MouseEventHandler, MouseEvent, useState } from 'react' 6 | import Logger, { LogEntry } from '../../components/logger'; 7 | import SampleHeader from '../../components/SampleHeader'; 8 | 9 | export default function PubSubClient() { 10 | 11 | const client = new Ably.Realtime ({ authUrl: '/token', authMethod: 'POST' }); 12 | 13 | return ( 14 | 15 | 16 |
17 |
18 | 19 |
20 | Publish messages on channels and subscribe to channels to receive messages. Click Publish from Client to publish a message on a channel from the web browser client. Click Publish from Server to publish a message from a serverless function. 21 |
22 | 23 |
24 |
25 |
26 |
27 | ) 28 | } 29 | 30 | function PubSubMessages() { 31 | 32 | const [logs, setLogs] = useState>([]) 33 | 34 | const { channel } = useChannel("status-updates", (message: Ably.Message) => { 35 | setLogs(prev => [...prev, new LogEntry(`✉️ event name: ${message.name} text: ${message.data.text}`)]) 36 | }); 37 | 38 | const [messageText, setMessageText] = useState('A message') 39 | 40 | const publicFromClientHandler: MouseEventHandler = (_event: MouseEvent) => { 41 | if(channel === null) return 42 | channel.publish('update-from-client', {text: `${messageText} @ ${new Date().toISOString()}`}) 43 | } 44 | 45 | const publicFromServerHandler: MouseEventHandler = (_event: MouseEvent) => { 46 | fetch('/publish', { 47 | 'method': 'POST', 48 | 'headers': { 49 | 'content-type': 'application/json', 50 | }, 51 | 'body': JSON.stringify({text: `${messageText} @ ${new Date().toISOString()}`}) 52 | }) 53 | } 54 | 55 | return ( 56 | <> 57 |
58 |
59 | Message text 60 |
61 | setMessageText(e.target.value)} /> 62 |
63 |
64 |
65 | 66 |
67 |
68 |
69 |
70 | 71 |
72 |
73 |
74 |
75 | 76 | 77 | ) 78 | } -------------------------------------------------------------------------------- /app/publish/route.ts: -------------------------------------------------------------------------------- 1 | import { NextRequest, NextResponse } from 'next/server' 2 | import * as Ably from "ably" 3 | 4 | export async function POST(req: Request) { 5 | if (!process.env.ABLY_API_KEY) { 6 | return NextResponse.json({ errorMessage: `Missing ABLY_API_KEY environment variable. 7 | If you're running locally, please ensure you have a ./.env file with a value for ABLY_API_KEY=your-key. 8 | If you're running in Netlify, make sure you've configured env variable ABLY_API_KEY. 9 | Please see README.md for more details on configuring your Ably API Key.`, 10 | },{ 11 | status: 500, 12 | headers: new Headers({ 13 | "content-type": "application/json" 14 | }) 15 | }); 16 | } 17 | 18 | const client = new Ably.Rest(process.env.ABLY_API_KEY) 19 | 20 | var channel = client.channels.get('status-updates') 21 | const message: { text: string } = await req.json() 22 | 23 | // By publishing via the serverless function you can perform 24 | // checks in a trusted environment on the data being published 25 | const disallowedWords = [ 'foo', 'bar', 'fizz', 'buzz' ] 26 | 27 | const containsDisallowedWord = disallowedWords.some(word => { 28 | return message.text.match(new RegExp(`\\b${word}\\b`)) 29 | }) 30 | 31 | if(containsDisallowedWord) { 32 | return new Response("", { 'status': 403 }); 33 | } 34 | 35 | await channel.publish('update-from-server', message) 36 | return new Response(""); 37 | } 38 | -------------------------------------------------------------------------------- /app/token/route.ts: -------------------------------------------------------------------------------- 1 | import { NextRequest, NextResponse } from 'next/server' 2 | import * as Ably from "ably"; 3 | 4 | export async function POST(req: Request) { 5 | if (!process.env.ABLY_API_KEY) { 6 | return NextResponse.json({ errorMessage: `Missing ABLY_API_KEY environment variable. 7 | If you're running locally, please ensure you have a ./.env file with a value for ABLY_API_KEY=your-key. 8 | If you're running in Netlify, make sure you've configured env variable ABLY_API_KEY. 9 | Please see README.md for more details on configuring your Ably API Key.`, 10 | },{ 11 | status: 500, 12 | headers: new Headers({ 13 | "content-type": "application/json" 14 | }) 15 | }); 16 | } 17 | 18 | const clientId = ( (await req.formData()).get('clientId')?.toString() ) || process.env.DEFAULT_CLIENT_ID || "NO_CLIENT_ID"; 19 | const client = new Ably.Rest(process.env.ABLY_API_KEY); 20 | const tokenRequestData = await client.auth.createTokenRequest({ clientId: clientId }); 21 | console.log(tokenRequestData) 22 | return NextResponse.json(tokenRequestData) 23 | } 24 | -------------------------------------------------------------------------------- /components/FooterItem.tsx: -------------------------------------------------------------------------------- 1 | export default function FooterItem(props : { menuItemText:string, menuItemLink:string }) { 2 | return ( 3 | 10 | ) 11 | } -------------------------------------------------------------------------------- /components/MenuItem.tsx: -------------------------------------------------------------------------------- 1 | interface MenuItemProps { 2 | menuItemText:string, 3 | menuItemActive:boolean, 4 | menuItemLink:string 5 | } 6 | 7 | export default function MenuItem(props:MenuItemProps) { 8 | return ( 9 | 16 | ) 17 | } -------------------------------------------------------------------------------- /components/SampleHeader.tsx: -------------------------------------------------------------------------------- 1 | export default function SampleHeader(props: { sampleName:string, sampleIcon:string, sampleDocsLink:string }) { 2 | return ( 3 |
4 |
5 |
6 |
7 | {props.sampleName} 8 |
9 |
10 |
11 | {props.sampleName} 12 |
13 |
14 | 31 |
32 | ); 33 | } 34 | -------------------------------------------------------------------------------- /components/Sidebar.tsx: -------------------------------------------------------------------------------- 1 | import FooterItem from "./FooterItem"; 2 | import MenuItem from "./MenuItem"; 3 | import SocialItem from "./SocialItem"; 4 | 5 | export default function Sidebar(props: { pageId: string; }) { 6 | 7 | const menuItems = [ 8 | { 9 | menuItemId: "Start", 10 | menuItemText: "Start", 11 | menuItemActive: false, 12 | menuItemLink: '/' 13 | }, 14 | { 15 | menuItemId: "Authentication", 16 | menuItemText: "Authentication", 17 | menuItemActive: false, 18 | menuItemLink: '/authentication' 19 | }, 20 | { 21 | menuItemId: "PubSubChannels", 22 | menuItemText: "Pub/Sub Channels", 23 | menuItemActive: false, 24 | menuItemLink: '/pub-sub' 25 | }, 26 | { 27 | menuItemId: "Presence", 28 | menuItemText: "Presence", 29 | menuItemActive: false, 30 | menuItemLink: '/presence' 31 | }, 32 | { 33 | menuItemId: "History", 34 | menuItemText: "History", 35 | menuItemActive: false, 36 | menuItemLink: '/history' 37 | } 38 | ] 39 | 40 | const footerItems = [ 41 | { 42 | menuItemText: "View our Docs", 43 | menuItemLink: 'https://ably.com/docs/' 44 | }, 45 | { 46 | menuItemText: "Explore Pub/Sub Channels", 47 | menuItemLink: 'https://ably.com/channels' 48 | }, 49 | { 50 | menuItemText: "ably.com", 51 | menuItemLink: 'https://ably.com/' 52 | }, 53 | ]; 54 | 55 | const socialItems = [ 56 | { 57 | menuItemText: "X (Twitter)", 58 | menuItemLink: 'https://twitter.com/ablyrealtime/', 59 | menuItemIcon: , 60 | menuItemFillSyles: 'fill-black' 61 | }, 62 | { 63 | menuItemText: "Github", 64 | menuItemLink: 'https://github.com/ably/', 65 | menuItemIcon: , 66 | menuItemFillSyles: 'fill-black' 67 | }, 68 | { 69 | menuItemText: "LinkedIn", 70 | menuItemLink: 'https://linkedin.com/company/ably-realtime/', 71 | menuItemIcon: , 72 | menuItemFillSyles: 'fill-black hover:fill-linkedin' 73 | }, 74 | { 75 | menuItemText: "Discord", 76 | menuItemLink: 'http://go.ably.com/discord', 77 | menuItemIcon: , 78 | menuItemFillSyles: 'fill-black hover:fill-discord' 79 | }, 80 | 81 | ]; 82 | 83 | return( 84 |
85 |
86 | AblyLogoWithText 87 |
88 | {menuItems.map( 89 | ({ 90 | menuItemId, 91 | menuItemText, 92 | menuItemLink 93 | }) => ( 94 | 100 | ) 101 | )} 102 |
103 |
104 |
105 | Rule 106 |
107 | {footerItems.map(({ menuItemText, menuItemLink }) => ( 108 | 109 | ))} 110 |
111 | Rule 112 |
113 | {socialItems.map( 114 | ({ 115 | menuItemText, 116 | menuItemIcon, 117 | menuItemLink, 118 | menuItemFillSyles 119 | }) => ( 120 | 126 | ) 127 | )} 128 | 129 |
130 |
131 |
132 | ) 133 | } -------------------------------------------------------------------------------- /components/SocialItem.tsx: -------------------------------------------------------------------------------- 1 | 2 | export default function SocialItem(props : { menuItemIconSource:any, menuItemLink:string, menuItemFillSyles:string }) { 3 | return ( 4 | 11 | ) 12 | } 13 | 14 | -------------------------------------------------------------------------------- /components/logger.tsx: -------------------------------------------------------------------------------- 1 | export class LogEntry { 2 | public timestamp: Date 3 | public message: string 4 | 5 | constructor(message: string) { 6 | this.timestamp = new Date() 7 | this.message = message 8 | } 9 | } 10 | 11 | export type LoggingProps = { 12 | logEntries: Array, 13 | displayHeader: boolean 14 | } 15 | 16 | export default function Logger({ logEntries, displayHeader }: LoggingProps) { 17 | return ( 18 |
19 | { displayHeader && 20 |
21 | Message log 22 |
23 | } 24 |
25 |
26 |
27 | Red 28 | Yellow 29 | Green 30 |
31 |
32 | 33 |
34 |
35 |
    36 | { 37 | // Show the newest log entry at the top 38 | logEntries.map((logEntry: LogEntry, index: number) => { 39 | return ( 40 |
  • 41 | {index+1}  {logEntry.message} 42 |
  • 43 | )} 44 | ) 45 | } 46 |
47 |
48 |
49 |
50 |
51 | ) 52 | } -------------------------------------------------------------------------------- /media/ably-nextjs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ably-labs/ably-nextjs-fundamentals-kit/8f7fead7ea32efc27e99fbd06708cd413f7eea76/media/ably-nextjs.png -------------------------------------------------------------------------------- /next.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('next').NextConfig} */ 2 | const nextConfig = { 3 | // disabling strict mode since the examples use 4 | // useEffect with no dependencies to ensure the function 5 | // is only run once and only run on the client. 6 | reactStrictMode: false, 7 | swcMinify: true, 8 | images: { 9 | dangerouslyAllowSVG: true, 10 | domains: ['static.ably.dev'], 11 | }, 12 | experimental: { 13 | serverComponentsExternalPackages: ['ably'], 14 | }, 15 | }; 16 | 17 | module.exports = nextConfig; 18 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ably-nextjs-fundamentals-kit", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "dev": "next dev", 7 | "dev:turbo": "next dev --turbo", 8 | "build": "next build", 9 | "start": "next start", 10 | "lint": "next lint" 11 | }, 12 | "dependencies": { 13 | "@types/node": "20.6.5", 14 | "@types/react": "18.2.22", 15 | "@types/react-dom": "18.2.7", 16 | "ably": "^2.0.1", 17 | "dotenv": "^16.0.3", 18 | "eslint": "8.50.0", 19 | "flowbite": "^1.8.1", 20 | "flowbite-react": "^0.6.1", 21 | "next": "^14.1.4", 22 | "random-names-generator": "^1.0.2", 23 | "react": "^18.2.0", 24 | "react-dom": "^18.2.0", 25 | "tailwind-scrollbar": "^3.0.5", 26 | "typescript": "5.2.2" 27 | }, 28 | "devDependencies": { 29 | "autoprefixer": "^10.4.15", 30 | "eslint-config-next": "^14.1.4", 31 | "eslint-plugin-react-hooks": "^4.6.0", 32 | "postcss": "^8.4.28", 33 | "tailwindcss": "^3.3.3" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | } 7 | -------------------------------------------------------------------------------- /public/ably-logo-col-horiz-rgb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ably-labs/ably-nextjs-fundamentals-kit/8f7fead7ea32efc27e99fbd06708cd413f7eea76/public/ably-logo-col-horiz-rgb.png -------------------------------------------------------------------------------- /public/ably-logo-col-horiz-rgb.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /public/ably-logo-col-inv-horiz-rgb.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /public/ably-motif-col-rgb.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /public/assets/AblyLogo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /public/assets/AblyLogoWithText.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /public/assets/Alert.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /public/assets/ArrowRight.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /public/assets/Authentication.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /public/assets/DiscordLogo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /public/assets/ExploreNow.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /public/assets/GithubLogo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /public/assets/GreenButton.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /public/assets/History.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /public/assets/HorizontalRule.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /public/assets/LinkedInLogo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /public/assets/NextjsLogo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /public/assets/PlusSign.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /public/assets/Presence.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /public/assets/PubSubChannels.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /public/assets/RedButton.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /public/assets/XTwitterLogo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /public/assets/YellowButton.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /public/assets/icon-social-discord-col.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /public/assets/icon-social-github-col.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /public/assets/icon-social-linkedin-col.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /public/assets/icon-social-x-col.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /public/vercel.svg: -------------------------------------------------------------------------------- 1 | 3 | 4 | -------------------------------------------------------------------------------- /random-names-generator.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'random-names-generator'; -------------------------------------------------------------------------------- /tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | module.exports = { 3 | content: [ 4 | "./app/**/*.{js,ts,jsx,tsx,mdx}", 5 | "./pages/**/*.{js,ts,jsx,tsx,mdx}", 6 | "./components/**/*.{js,ts,jsx,tsx,mdx}", 7 | 8 | // Or if using `src` directory: 9 | "./src/**/*.{js,ts,jsx,tsx,mdx}", 10 | ], 11 | theme: { 12 | fontFamily: { 13 | "manrope": "Manrope, sans-serif", 14 | "jetbrains-mono": "'JetBrains Mono', monospace", 15 | }, 16 | extend: { 17 | colors: { 18 | 'linkedin':'#1269BF', 19 | 'discord':'#5B64EA' 20 | } 21 | }, 22 | }, 23 | plugins: [ 24 | require('tailwind-scrollbar'), 25 | ], 26 | } 27 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": [ 5 | "dom", 6 | "dom.iterable", 7 | "esnext" 8 | ], 9 | "allowJs": true, 10 | "skipLibCheck": true, 11 | "strict": true, 12 | "forceConsistentCasingInFileNames": true, 13 | "noEmit": true, 14 | "esModuleInterop": true, 15 | "module": "esnext", 16 | "moduleResolution": "node", 17 | "resolveJsonModule": true, 18 | "isolatedModules": true, 19 | "allowImportingTsExtensions":true, 20 | "jsx": "preserve", 21 | "incremental": true, 22 | "plugins": [ 23 | { 24 | "name": "next" 25 | } 26 | ] 27 | }, 28 | "include": [ 29 | "next-env.d.ts", 30 | "**/*.ts", 31 | "**/*.tsx", 32 | ".next/types/**/*.ts" 33 | , "components/layout.tsx", "pages/pub-sub.old", "pages/index.old", "app/page.tsx.old", "app/pub-sub/pubsub-client.tsx.old" ], 34 | "exclude": [ 35 | "node_modules" 36 | ] 37 | } 38 | -------------------------------------------------------------------------------- /vercel.json: -------------------------------------------------------------------------------- 1 | { 2 | "framework": "nextjs" 3 | } --------------------------------------------------------------------------------