This provides a simple example of how to use ably-js
from within a Web Worker, following the instructions in ably-js
’s README
.
It was written for manually testing the Webpack version 5 migration in ably/ably-js#1184, but I think serves as a generally useful example.
- Copy
.env.example
to.env
, and replaceinsert_key_here
with your Ably API key. - Run
npm install
. - Run
npm run serve
. This will launch a web browser.
You should see the following log messages in your browser’s console (the last two may appear in the opposite order):
Hello World, from worker!
Attached to channel
Published to Ably
Got message from Ably
These steps use npm pack
, which emits a .tgz
file similar to that uploaded by npm publish
.
- Check out the
ably-js
repository at the commit you wish to test. - At the root of the
ably-js
repository, runnpm run build && npm pack --pack-destination <path>
, where<path>
is the directory you wish to output the.tgz
file to. - In the current repository, change the
package.json
’sdependencies.ably
entry to"file:<tgz-file-path>"
, where<tgz-file-path>
is the path to the.tgz
file output by the previous step. - Run
npm install
.