Skip to content

Commit

Permalink
chore: downgrade emittery for cjs compatiblity (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
fern-support authored Dec 6, 2024
1 parent 6fa39c9 commit 015d941
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 71 deletions.
104 changes: 52 additions & 52 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,55 @@ name: ci
on: [push]

jobs:
compile:
runs-on: ubuntu-latest

steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Set up node
uses: actions/setup-node@v3

- name: Compile
run: yarn && yarn build

test:
runs-on: ubuntu-latest

steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Set up node
uses: actions/setup-node@v3

- name: Compile
run: yarn && yarn test

publish:
needs: [ compile, test ]
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Set up node
uses: actions/setup-node@v3
- name: Install dependencies
run: yarn install
- name: Build
run: yarn build

- name: Publish to npm
run: |
npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
if [[ ${GITHUB_REF} == *alpha* ]]; then
npm publish --access public --tag alpha
elif [[ ${GITHUB_REF} == *beta* ]]; then
npm publish --access public --tag beta
else
npm publish --access public
fi
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
compile:
runs-on: ubuntu-latest

steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Set up node
uses: actions/setup-node@v3

- name: Compile
run: yarn && yarn build

test:
runs-on: ubuntu-latest

steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Set up node
uses: actions/setup-node@v3

- name: Compile
run: yarn && yarn test

publish:
needs: [compile, test]
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Set up node
uses: actions/setup-node@v3
- name: Install dependencies
run: yarn install
- name: Build
run: yarn build

- name: Publish to npm
run: |
npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
if [[ ${GITHUB_REF} == *alpha* ]]; then
npm publish --access public --tag alpha
elif [[ ${GITHUB_REF} == *beta* ]]; then
npm publish --access public --tag beta
else
npm publish --access public
fi
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ const websocket = cartesia.tts.websocket({
});

try {
await websocket.connect({
// If using Node.js, you can pass a custom WebSocket constructor, such as from `ws`.
// This is not needed for browser usage, so you can call connect() without any arguments.
WebSocket: WS,
});
await websocket.connect();
} catch (error) {
console.error(`Failed to connect to Cartesia: ${error}`);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"qs": "6.11.2",
"readable-stream": "^4.5.2",
"form-data-encoder": "^4.0.2",
"emittery": "^1.0.3",
"emittery": "^0.13.1",
"human-id": "^4.1.1",
"ws": "^8.15.13"
},
Expand Down
13 changes: 10 additions & 3 deletions src/wrapper/Websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
WebSocketOptions,
EmitteryCallbacks,
} from "./utils";
import { Tts } from "api/resources/tts/client/Client";
import { Tts } from "../api/resources/tts/client/Client";
import Source from "./source";
import qs from "qs";

Expand All @@ -41,9 +41,16 @@ export default class Websocket {
* If set to `0`, the stream will not time out.
* @returns A Source object that can be passed to a Player to play the audio.
* @returns An Emittery instance that emits messages from the WebSocket.
* @returns An abort function that can be called to cancel the stream.
*/
send(inputs: WebSocketTtsRequest, { timeout = 0 }: WebSocketStreamOptions = {}) {
async send(
inputs: WebSocketTtsRequest,
{ timeout = 0 }: WebSocketStreamOptions = {}
): Promise<
EmitteryCallbacks<{
message: string;
timestamps: WordTimestamps;
}> & { source: Source; stop: unknown }
> {
if (!this.#isConnected) {
throw new Error("Not connected to WebSocket. Call .connect() first.");
}
Expand Down
8 changes: 4 additions & 4 deletions src/wrapper/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ export default class Source {
#encoding: RawEncoding;
#container: string;

on = this.#emitter.on.bind(this.#emitter);
once = this.#emitter.once.bind(this.#emitter);
events = this.#emitter.events.bind(this.#emitter);
off = this.#emitter.off.bind(this.#emitter);
on: Emittery<SourceEventData>["on"] = this.#emitter.on.bind(this.#emitter);
once: Emittery<SourceEventData>["once"] = this.#emitter.once.bind(this.#emitter);
events: Emittery<SourceEventData>["events"] = this.#emitter.events.bind(this.#emitter);
off: Emittery<SourceEventData>["off"] = this.#emitter.off.bind(this.#emitter.off);

/**
* Create a new Source.
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"extendedDiagnostics": true,
"strict": true,
"target": "ES6",
"module": "esnext",
"module": "CommonJS",
"moduleResolution": "node",
"esModuleInterop": true,
"skipLibCheck": true,
Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1303,11 +1303,6 @@ emittery@^0.13.1:
resolved "https://registry.yarnpkg.com/emittery/-/emittery-0.13.1.tgz#c04b8c3457490e0847ae51fced3af52d338e3dad"
integrity sha512-DeWwawk6r5yR9jFgnDKYt4sLS0LmHJJi3ZOnb5/JdbYwj3nW+FxQnHIjhBKz8YLC7oRNPVM9NQ47I3CVx34eqQ==

emittery@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/emittery/-/emittery-1.0.3.tgz#c9d2a9c689870f15251bb13b31c67715c26d69ac"
integrity sha512-tJdCJitoy2lrC2ldJcqN4vkqJ00lT+tOWNT1hBJjO/3FDMJa5TTIiYGCKGkn/WfCyOzUMObeohbVTj00fhiLiA==

emoji-regex@^8.0.0:
version "8.0.0"
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37"
Expand Down

0 comments on commit 015d941

Please sign in to comment.