@canxjs/echo is a client-side library for subscribing to channels and listening to events broadcast by your CanxJS server.
@canxjs/echo
1npm install @canxjs/echo socket.io-client
npm install @canxjs/echo socket.io-client
Initialize Echo in your client-side application (e.g., React, Vue, or vanilla JS).
1import Echo from "@canxjs/echo";2import io from "socket.io-client";34const echo = new Echo({5 broadcaster: "socket.io",6 host: "http://localhost:3000",7 client: io8});
import Echo from "@canxjs/echo";
import io from "socket.io-client";
const echo = new Echo({
broadcaster: "socket.io",
host: "http://localhost:3000",
client: io
});
1// Listen to a public channel2echo.channel("orders")3 .listen("OrderShipped", (e) => {4 console.log(e.order.name);5 });
// Listen to a public channel
echo.channel("orders")
.listen("OrderShipped", (e) => {
console.log(e.order.name);
For private channels, authentication is handled automatically.
1// Private channels (auth handled automatically)2echo.private("user.1")3 .listen("NotificationReceived", (e) => {4 // ...5 });
// Private channels (auth handled automatically)
echo.private("user.1")
.listen("NotificationReceived", (e) => {
// ...
1echo.leave("orders");
echo.leave("orders");
Explore more real-time and enterprise features.