Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions packages/react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
You must call this function somewhere in your app _before_ you use `useEcho` in a component to configure your Echo instance. You only need to pass the required data:

```ts
import Pusher from "pusher-js";
import { configureEcho } from "@laravel/echo-react";

configureEcho({
broadcaster: "reverb",
Pusher,
});
```

Expand Down
3 changes: 0 additions & 3 deletions packages/react/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import Echo, {
type Broadcaster,
type EchoOptions,
} from "laravel-echo";
import Pusher from "pusher-js";
import type { ConfigDefaults } from "../types";

/**
Expand All @@ -25,8 +24,6 @@ const getEchoInstance = <T extends keyof Broadcaster>(): Echo<T> => {
);
}

echoConfig.Pusher ??= Pusher;

echoInstance = new Echo<keyof Broadcaster>(echoConfig);

return echoInstance as Echo<T>;
Expand Down
35 changes: 35 additions & 0 deletions packages/react/tests/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,39 @@ describe("echo helper", () => {
expect(instance.connector).toBeInstanceOf(CustomConnector);
expect(instance.options.authEndpoint).toBe("/custom/auth");
});

it("configures a non-Pusher broadcaster without requiring pusher-js", async () => {
const { configureEcho, echo } = await import("../src/config");

configureEcho({
broadcaster: "mercure",
host: "http://localhost/.well-known/mercure",
});

expect(echo()).toBeDefined();
expect(echo().options.broadcaster).toBe("mercure");
expect(echo().options.Pusher).toBeUndefined();
});

it("uses a Pusher client passed to configureEcho", async () => {
const { configureEcho, echo } = await import("../src/config");

class FakePusher {
constructor(
public key: string,
public options: unknown,
) {}
}

configureEcho<"reverb">({
broadcaster: "reverb",
key: "app-key",
Pusher: FakePusher as never,
});

const instance = echo<"reverb">();

expect(instance.options.Pusher).toBe(FakePusher);
expect(instance.connector.pusher).toBeInstanceOf(FakePusher);
});
});
2 changes: 2 additions & 0 deletions packages/svelte/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
You must call this function somewhere in your app _before_ you use `useEcho` in a component to configure your Echo instance. You only need to pass the required data:

```ts
import Pusher from "pusher-js";
import { configureEcho } from "@laravel/echo-svelte";

configureEcho({
broadcaster: "reverb",
Pusher,
});
```

Expand Down
3 changes: 0 additions & 3 deletions packages/svelte/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import Echo, {
type Broadcaster,
type EchoOptions,
} from "laravel-echo";
import Pusher from "pusher-js";
import type { ConfigDefaults } from "../types";

/**
Expand All @@ -25,8 +24,6 @@ const getEchoInstance = <T extends keyof Broadcaster>(): Echo<T> => {
);
}

echoConfig.Pusher ??= Pusher;

echoInstance = new Echo<keyof Broadcaster>(echoConfig);

return echoInstance as Echo<T>;
Expand Down
35 changes: 35 additions & 0 deletions packages/svelte/tests/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,39 @@ describe("echo helper", () => {
expect(instance.connector).toBeInstanceOf(CustomConnector);
expect(instance.options.authEndpoint).toBe("/custom/auth");
});

it("configures a non-Pusher broadcaster without requiring pusher-js", async () => {
const { configureEcho, echo } = await import("../src/config");

configureEcho({
broadcaster: "mercure",
host: "http://localhost/.well-known/mercure",
});

expect(echo()).toBeDefined();
expect(echo().options.broadcaster).toBe("mercure");
expect(echo().options.Pusher).toBeUndefined();
});

it("uses a Pusher client passed to configureEcho", async () => {
const { configureEcho, echo } = await import("../src/config");

class FakePusher {
constructor(
public key: string,
public options: unknown,
) {}
}

configureEcho<"reverb">({
broadcaster: "reverb",
key: "app-key",
Pusher: FakePusher as never,
});

const instance = echo<"reverb">();

expect(instance.options.Pusher).toBe(FakePusher);
expect(instance.connector.pusher).toBeInstanceOf(FakePusher);
});
});
2 changes: 2 additions & 0 deletions packages/vue/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
You must call this function somewhere in your app _before_ you use `useEcho` in a component to configure your Echo instance. You only need to pass the required data:

```ts
import Pusher from "pusher-js";
import { configureEcho } from "@laravel/echo-vue";

configureEcho({
broadcaster: "reverb",
Pusher,
});
```

Expand Down
3 changes: 0 additions & 3 deletions packages/vue/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import Echo, {
type Broadcaster,
type EchoOptions,
} from "laravel-echo";
import Pusher from "pusher-js";
import type { ConfigDefaults } from "../types";

/**
Expand All @@ -25,8 +24,6 @@ const getEchoInstance = <T extends keyof Broadcaster>(): Echo<T> => {
);
}

echoConfig.Pusher ??= Pusher;

echoInstance = new Echo<keyof Broadcaster>(echoConfig);

return echoInstance as Echo<T>;
Expand Down
35 changes: 35 additions & 0 deletions packages/vue/tests/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,39 @@ describe("echo helper", async () => {
expect(instance.connector).toBeInstanceOf(CustomConnector);
expect(instance.options.authEndpoint).toBe("/custom/auth");
});

it("configures a non-Pusher broadcaster without requiring pusher-js", async () => {
const { configureEcho, echo } = await import("../src/config");

configureEcho({
broadcaster: "mercure",
host: "http://localhost/.well-known/mercure",
});

expect(echo()).toBeDefined();
expect(echo().options.broadcaster).toBe("mercure");
expect(echo().options.Pusher).toBeUndefined();
});

it("uses a Pusher client passed to configureEcho", async () => {
const { configureEcho, echo } = await import("../src/config");

class FakePusher {
constructor(
public key: string,
public options: unknown,
) {}
}

configureEcho<"reverb">({
broadcaster: "reverb",
key: "app-key",
Pusher: FakePusher as never,
});

const instance = echo<"reverb">();

expect(instance.options.Pusher).toBe(FakePusher);
expect(instance.connector.pusher).toBeInstanceOf(FakePusher);
});
});
Loading