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

Merge main into integration/v2 #1480

Merged
merged 68 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
5baf94d
Support presence message extras
lmars Aug 2, 2023
99f7798
Add PresenceMessage.fromValues to ably.d.ts
lmars Aug 6, 2023
40f890b
Merge pull request #1418 from ably/presence-extras
lmars Aug 8, 2023
3695410
docs: update changelog for 1.2.43 release
owenpearson Aug 10, 2023
dac4aad
chore: bump version for 1.2.43 release
owenpearson Aug 10, 2023
cfdeda0
Merge pull request #1420 from ably/release/1.2.43
owenpearson Aug 10, 2023
d96c33d
Export the ErrorInfo class
lmars Aug 23, 2023
55182b8
Merge pull request #1430 from ably/export-errorinfo
lmars Aug 24, 2023
1b088b2
feat: move react-hooks into ably-js
owenpearson Aug 30, 2023
49173e7
docs: mark the react hooks as experimental
owenpearson Sep 4, 2023
dd8595f
Merge pull request #1433 from ably/react-hooks
owenpearson Sep 4, 2023
8dad7d9
docs: update CHANGELOG for 1.2.44 release
owenpearson Sep 4, 2023
10f445e
chore: bump version for 1.2.44 release
owenpearson Sep 4, 2023
9c90fe5
Merge pull request #1434 from ably/release/1.2.44
owenpearson Sep 4, 2023
183529c
cleanup: remove react-hooks license
owenpearson Sep 4, 2023
f4c2119
cleanup: merge react-hooks and root CONTRIBUTING guides
owenpearson Sep 4, 2023
76a5475
Merge pull request #1435 from ably/remove-react-hooks-license
owenpearson Sep 4, 2023
185e253
README: Fix React categorisation and WebWorkers bug
mattheworiordan Sep 15, 2023
2743ae0
Update React docs
mattheworiordan Sep 15, 2023
8f10637
fix: send ably agent as header in react-hooks time ping
owenpearson Sep 18, 2023
093307e
Merge pull request #1440 from ably/mattheworiordan-react-docs-patch
owenpearson Sep 18, 2023
7ba842c
Merge pull request #1441 from ably/react-hooks-ping-agent-fix
owenpearson Sep 18, 2023
723b40c
docs: add docs for preventing warnings when used with NextJS
owenpearson Sep 19, 2023
b5f11de
refactor!: remove `AblyProvider` options prop
owenpearson Sep 21, 2023
1d38537
docs: add array -> object hook return values to react migration guide
owenpearson Sep 21, 2023
6e52d0e
Merge pull request #1444 from ably/nextjs-warnings-advice
owenpearson Sep 22, 2023
d735e23
Merge pull request #1446 from ably/remove-provider-options-prop
owenpearson Sep 22, 2023
ec653f1
Merge pull request #1447 from ably/react-migration-guide-update
owenpearson Sep 25, 2023
9181064
fix: throw descriptive error when callbacks used with react
owenpearson Sep 25, 2023
fbcd191
Merge pull request #1450 from ably/react-callbacks-error-message
owenpearson Sep 25, 2023
e80b21b
docs: update changelog for 1.2.45 release
owenpearson Sep 25, 2023
be0085d
chore: bump version for 1.2.45 release
owenpearson Sep 25, 2023
76cc74f
Merge pull request #1451 from ably/release/1.2.45
owenpearson Sep 25, 2023
2c94dbf
fix: add missing id param for useStateErrors call to useChannelStateL…
owenpearson Sep 29, 2023
688fbef
test: fix browser test rest_host query param
owenpearson Oct 4, 2023
89589f1
Merge pull request #1457 from ably/fix-test-env-rest_host-param
owenpearson Oct 4, 2023
4879d50
fix: wrap usePresence channel options in ref
owenpearson Oct 4, 2023
695e5bb
refactor: send react-hooks agent as channel param
owenpearson Oct 4, 2023
7c59b7d
Publish to new CDN bucket only
surminus Oct 5, 2023
a298240
refactor: make arrEvery callback params non-optional
owenpearson Oct 5, 2023
65ff5d7
refactor: add `arrEquals` util
owenpearson Oct 5, 2023
83b4516
Merge pull request #1460 from ably/laura-delete-old-cdn-bucket
owenpearson Oct 5, 2023
1de1a64
fix: don't double url encode agent transport param
owenpearson Oct 12, 2023
311726e
fix: avoid directly exporting Ably.ErrorInfo from promises.js
owenpearson Oct 17, 2023
374252c
Merge pull request #1463 from ably/fix-errorinfo-promise-export
owenpearson Oct 19, 2023
0d7dd24
Merge pull request #1462 from ably/fix-double-encoded-agent
owenpearson Oct 19, 2023
f38c5a7
fix: improve channel options reattachment logic
owenpearson Oct 5, 2023
a35b65c
Merge pull request #1459 from ably/react-hooks-agent-channel-param
owenpearson Oct 19, 2023
dfe425c
Fix RealtimePresence#leave handling of PresenceMessage argument
lawrence-forooghian Oct 20, 2023
292c0f3
deps: bump ws to 8.14.2
owenpearson Oct 23, 2023
c3bac03
Merge pull request #1455 from ably/fix-use-state-errors-missing-id-param
owenpearson Oct 23, 2023
6855073
doc(README): remove typo
Chaitanya110703 Oct 23, 2023
73a86a3
Merge pull request #1466 from ably/1465-presence-leave-handle-presenc…
lawrence-forooghian Oct 23, 2023
0e99593
Merge pull request #1468 from Chaitanya110703/patch-1
owenpearson Oct 24, 2023
5725e73
Merge pull request #1467 from ably/upgrade-ws
owenpearson Oct 24, 2023
aaca8b6
chore: bump version for 1.2.46 release
owenpearson Oct 24, 2023
5dcdd97
chore: update changelog for 1.2.46 release
owenpearson Oct 24, 2023
e3e6781
Merge pull request #1471 from ably/release/1.2.46
owenpearson Oct 25, 2023
ddef9f7
Turn off continue-on-error for browser jobs
lawrence-forooghian Nov 1, 2023
16d620c
fix: don't compare `agent` channel param when determining whether cha…
Nov 1, 2023
2d839b4
fix(react): ensure channel options are passed to channel state listen…
Nov 1, 2023
d6978ca
Merge pull request #1479 from ably/browser-failure-email-notifications
lawrence-forooghian Nov 1, 2023
5857e59
Merge pull request #1478 from ably/react-channel-options-fix
owenpearson Nov 1, 2023
47fe269
chore: update changelog for 1.2.47 release
Nov 2, 2023
edd50b0
chore: bump version for 1.2.47 release
Nov 2, 2023
b87ac65
Merge pull request #1481 from ably/release/1.2.47
owenpearson Nov 2, 2023
54932b4
Upgrade Playwright to 1.39.0
lawrence-forooghian Nov 3, 2023
68bf030
Merge remote-tracking branch 'origin/main' into 2023-11-01-merge-main…
lawrence-forooghian Nov 1, 2023
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
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ module.exports = {
"tools",
"scripts",
"docs",
"react",
"Gruntfile.js",
],
settings: {
Expand Down
22 changes: 1 addition & 21 deletions .github/workflows/publish-cdn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,6 @@ on:

jobs:
publish:
runs-on: ubuntu-latest
# These permissions are necessary to run the configure-aws-credentials action
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.inputs.version }}
- uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: arn:aws:iam::${{ secrets.ABLY_AWS_ACCOUNT_ID_PRODUCTION }}:role/github-actions-sdk
aws-region: us-east-1
- name: Use Node.js 14.x
uses: actions/setup-node@v1
with:
node-version: 14.x
- run: npm ci
- run: node scripts/cdn_deploy.js --skipCheckout --tag=${{ github.event.inputs.version }}
publish_sdk:
runs-on: ubuntu-latest
# These permissions are necessary to run the configure-aws-credentials action
permissions:
Expand All @@ -48,4 +28,4 @@ jobs:
with:
node-version: 14.x
- run: npm ci
- run: node scripts/cdn_deploy.js --bucket prod-cdn.ably.com --skipCheckout --tag=${{ github.event.inputs.version }}
- run: node scripts/cdn_deploy.js --skipCheckout --tag=${{ github.event.inputs.version }}
20 changes: 20 additions & 0 deletions .github/workflows/react.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Test (react hooks)

on:
workflow_dispatch:
pull_request:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 16
- run: npm ci
- run: npm run format:check
- run: npm run test:react
6 changes: 3 additions & 3 deletions .github/workflows/test-browser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ on:
jobs:
test-browser:
runs-on: ubuntu-20.04
continue-on-error: true
strategy:
fail-fast: false
matrix:
browser: [chromium, firefox, webkit]
steps:
Expand All @@ -25,8 +25,8 @@ jobs:
with:
node-version: 16.x
- run: npm ci
- name: Install playwright dependencies
run: sudo npx playwright install-deps
- name: Install Playwright browsers and dependencies
run: npx playwright install --with-deps
- env:
PLAYWRIGHT_BROWSER: ${{ matrix.browser }}
run: npm run test:playwright
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ node_modules
npm-debug.log
.tool-versions
build/
react/
docs/generated/
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,32 @@

This contains only the most important and/or user-facing changes; for a full changelog, see the commit history.

## [1.2.47](https://github.com/ably/ably-js/tree/1.2.47) (2023-11-02)

- fix(react): fix issue where useChannel would error upon router navigation or hmr [\#1478](https://github.com/ably/ably-js/pull/1478)

## [1.2.46](https://github.com/ably/ably-js/tree/1.2.46) (2023-10-24)

- fix: avoid directly exporting Ably.ErrorInfo from promises.js [\#1463](https://github.com/ably/ably-js/pull/1463)
- fix(react): add missing id param for `useStateErrors` call to `useChannelStateListener` [\#1455](https://github.com/ably/ably-js/pull/1455)
- fix: allow `RealtimePresence#leave` to take `PresenceMessage` as argument [\#1466](https://github.com/ably/ably-js/pull/1466)
- deps: bump ws to 8.14.2 [\#1467](https://github.com/ably/ably-js/pull/1467)

## [1.2.45](https://github.com/ably/ably-js/tree/1.2.45) (2023-09-25)

- remove `AblyProvider` options prop [\#1446](https://github.com/ably/ably-js/pull/1446)
- fix: throw descriptive error when callbacks used with react [\#1450](https://github.com/ably/ably-js/pull/1450)

## [1.2.44](https://github.com/ably/ably-js/tree/1.2.44) (2023-09-04)

- Add new experimental react hooks and context provider [\#1433](https://github.com/ably/ably-js/pull/1433)
- Export the `ErrorInfo` class [\#1430](https://github.com/ably/ably-js/pull/1430)

## [1.2.43](https://github.com/ably/ably-js/tree/1.2.43) (2023-08-10)

- Add REST APIs for batch publishing, batch presence, and token revocation [\#1410](https://github.com/ably/ably-js/pull/1410)
- Add support for presence message extras [\#1418](https://github.com/ably/ably-js/pull/1418)

## [1.2.42](https://github.com/ably/ably-js/tree/1.2.42) (2023-07-24)

- Auth: remain connected upon failed authorize unless returning explicit 403 [\#1385](https://github.com/ably/ably-js/pull/1385)
Expand Down
37 changes: 29 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
2. Create a new branch for the release, for example `release/1.2.3`
3. Update the CHANGELOG.md with any customer-affecting changes since the last release and add this to the git index
4. Run `npm version <VERSION_NUMBER> --no-git-tag-version` with the new version and add the changes to the git index
5. Create a PR for the release branch
6. Once the release PR is landed to the `main` branch, checkout the `main` branch locally (remember to pull the remote changes) and run `npm run build`
7. Run `git tag <VERSION_NUMBER>` with the new version and push the tag to git
8. Run `npm publish .` (should require OTP) - publishes to NPM
9. Run the GitHub action "Publish to CDN" with the new tag name
10. Visit https://github.com/ably/ably-js/tags and add release notes to the release (generally you can just copy the notes you added to the CHANGELOG)
11. For nontrivial releases: update the ably-js submodule ref in the realtime repo
12. Update the [Ably Changelog](https://changelog.ably.com/) (via [headwayapp](https://headwayapp.co/)) with these changes (again, you can just copy the notes you added to the CHANGELOG)
5. Update the version number to the new version in `src/platform/react-hooks/src/AblyReactHooks.ts`
6. Create a PR for the release branch
7. Once the release PR is landed to the `main` branch, checkout the `main` branch locally (remember to pull the remote changes) and run `npm run build`
8. Run `git tag <VERSION_NUMBER>` with the new version and push the tag to git
9. Run `npm publish .` (should require OTP) - publishes to NPM
10. Run the GitHub action "Publish to CDN" with the new tag name
11. Visit https://github.com/ably/ably-js/tags and add release notes to the release (generally you can just copy the notes you added to the CHANGELOG)
12. For nontrivial releases: update the ably-js submodule ref in the realtime repo
13. Update the [Ably Changelog](https://changelog.ably.com/) (via [headwayapp](https://headwayapp.co/)) with these changes (again, you can just copy the notes you added to the CHANGELOG)

## Building the library

Expand Down Expand Up @@ -107,3 +108,23 @@ When using the test webserver `npm run test:webserver` the following test variab
- `tls_port` - TLS port to use for the tests, defaults to 443
- `tls` - true or false to enable/disable use of TLS respectively
- `log_level` - Log level for the client libraries, defaults to 2, 4 is `MICRO`

## React hooks

The react sample application is configured to execute using Vite - which will load a sample web app that acts as a simple test harness for the hooks.

You can run the dev server from the terminal using:

```bash
npm run start:react
```

You'll need to provide an API key for the sample to work (or you'll just get a white page and some errors in the console). To do this, create the file `./src/platform/react-hooks/sample-app/.env` and add the following line:

```.env
VITE_ABLY_API_KEY=<your-api-key>
```

This API key will be loaded by the vite dev server at build time.

You can run the unit tests by running `npm run test:react` in the terminal.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ This SDK supports the following platforms:

**Node.js:** version 8.17 or newer. (1.1.x versions work on Node.js 4.5 or newer). We do not currently provide an ESM bundle, please [contact us](https://www.ably.com/contact) if you would would like to use ably-js in a NodeJS ESM project.

**React (release candidate)** We offer a set of React Hooks which make it seamless to use ably-js in your React application. See the [React Hooks documentation](./docs/react.md) for more details.

**React Native:** We aim to support all platforms supported by React Native. If you find any issues please raise an issue or [contact us](https://www.ably.com/contact).

**NativeScript:** see [ably-js-nativescript](https://github.com/ably/ably-js-nativescript)

**TypeScript:** see [below](#typescript)

**WebWorkers**: We build a separate bundle which supports running in a [Web Worker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) context. You can import it like this:

```js
import Ably from 'ably/build/ably-webworker.min';
```
Expand Down Expand Up @@ -231,7 +234,7 @@ can use

```javascript
await channel.presence.enterClient('myClientId', 'status');
// and similiarly, updateClient and leaveClient
// and similarly, updateClient and leaveClient
```

### Querying the Presence History
Expand Down
33 changes: 32 additions & 1 deletion ably.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@
/**
* A generic Ably error object that contains an Ably-specific status code, and a generic status code. Errors returned from the Ably server are compatible with the `ErrorInfo` structure and should result in errors that inherit from `ErrorInfo`.
*/
interface ErrorInfo extends Error {
class ErrorInfo extends Error {
/**
* Ably [error code](https://github.com/ably/ably-common/blob/main/protocol/errors.json).
*/
Expand All @@ -745,6 +745,20 @@
* HTTP Status Code corresponding to this error, where applicable.
*/
statusCode: number;
/**
* The underlying cause of the error, where applicable.
*/
cause?: string | Error | ErrorInfo;

/**
* Construct an ErrorInfo object.
*
* @param message - A string describing the error.
* @param code - Ably [error code](https://github.com/ably/ably-common/blob/main/protocol/errors.json).
* @param statusCode - HTTP Status Code corresponding to this error.
* @param cause - The underlying cause of the error.
*/
constructor(message: string, code: number, statusCode: number, cause?: string | Error | ErrorInfo);
}

/**
Expand Down Expand Up @@ -2347,8 +2361,8 @@
*/
get(name: string, channelOptions?: ChannelOptions): T;
/**
* @experimental This is a preview feature and may change in a future non-major release.

Check warning on line 2364 in ably.d.ts

View workflow job for this annotation

GitHub Actions / lint

Invalid JSDoc tag name "experimental"
* This experimental method allows you to create custom realtime data feeds by selectively subscribing

Check warning on line 2365 in ably.d.ts

View workflow job for this annotation

GitHub Actions / lint

Expected no lines between tags
* to receive only part of the data from the channel.
* See the [announcement post](https://pages.ably.com/subscription-filters-preview) for more information.
*
Expand Down Expand Up @@ -2495,6 +2509,10 @@
* This will typically be empty as all presence messages received from Ably are automatically decoded client-side using this value. However, if the message encoding cannot be processed, this attribute will contain the remaining transformations not applied to the data payload.
*/
encoding: string;
/**
* A JSON object of arbitrary key-value pairs that may contain metadata, and/or ancillary payloads. Valid payloads include `headers`.
*/
extras: any;
/**
* A unique ID assigned to each `PresenceMessage` by Ably.
*/
Expand Down Expand Up @@ -2523,6 +2541,14 @@
* @param channelOptions - A {@link ChannelOptions} object containing the cipher.
*/
fromEncodedArray: (JsonArray: any[], channelOptions?: ChannelOptions) => Promise<PresenceMessage[]>;

/**
* Initialises a `PresenceMessage` from a `PresenceMessage`-like object.
*
* @param values - The values to intialise the `PresenceMessage` from.
* @param stringifyAction - Whether to convert the `action` field from a number to a string.
*/
fromValues(values: PresenceMessage | Record<string, unknown>, stringifyAction?: boolean): PresenceMessage;
}

/**
Expand Down Expand Up @@ -2871,3 +2897,8 @@
* A client that extends the functionality of {@link Rest} and provides additional realtime-specific features.
*/
export declare class Realtime extends Types.Realtime {}

/**
* A generic Ably error object that contains an Ably-specific status code, and a generic status code. Errors returned from the Ably server are compatible with the `ErrorInfo` structure and should result in errors that inherit from `ErrorInfo`.
*/
export declare class ErrorInfo extends Types.ErrorInfo {}
50 changes: 50 additions & 0 deletions docs/react-migration-guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# React hooks upgrade / migration guide

## Version 2.x to 3.x

### Hooks now return object

In previous versions of our react hooks, the `useChannel` and `usePresence` hooks returned arrays.
Since these hooks now return more values we've opted to change them to return objects.
You can still access the return values using simple destructuring syntax like in the below example:

```jsx
const { channel, ably } = useChannel("your-channel-name", (message) => { /* ... */ });

const { presenceData, updateStatus } = usePresence("your-channel-name");
```

### Replacing `configureAbly` with `AblyProvider`

In versions 1 and 2 of our react-hooks, we exported a function called `configureAbly` which was used to register an Ably client instance to global state.
This caused a few issues (most notably it made the hooks difficult to use with hot module reloading), so we have replaced the global configuration function with a context provider (`AblyProvider`)
The simplest way to use the context provider is to create your own ably-js client outside and then pass it as a prop to the `AblyProvider`.
All child components of the `AblyProvider` will then be able to use the hooks, making use of the provided Ably client instance. For this reason, we recommend putting the `AblyProvider` high up in your component tree, surrounding all components which may need to use Ably hooks.

For example, replace this:
```jsx
configureAbly(options);
```

With this:
```jsx
const client = new Ably.Realtime(options);

return <AblyProvider client={ably}>
{children}
</AblyProvider>
```

If you were already using multiple Ably clients in the same react application, you may pass in an optional `id` prop to the provider, which you can then pass to the hooks to specify which Ably client instance the hook should use:
```jsx
const client = new Ably.Realtime(options);

return <AblyProvider client={ably} id="foo">
{children}
</AblyProvider>

// in a child component:
useChannel({channelName: 'my_channel', id: 'foo'}, (msg) => {
console.log(msg);
});
```
Loading
Loading