mirror of
https://github.com/LukeHagar/crossws.git
synced 2025-12-10 04:19:37 +00:00
chore: add new playground
This commit is contained in:
28
examples/h3/index.ts
Normal file
28
examples/h3/index.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { createApp, createRouter } from "h3";
|
||||
import { defineWebSocketHooks } from "crossws";
|
||||
|
||||
export const app = createApp();
|
||||
|
||||
// Listhen automatically sets up integration!
|
||||
// Learn more: https://crossws.unjs.io
|
||||
|
||||
export const websocket = defineWebSocketHooks({
|
||||
open(peer) {
|
||||
console.log("[ws] open", peer);
|
||||
},
|
||||
|
||||
message(peer, message) {
|
||||
console.log("[ws] message", peer, message);
|
||||
if (message.text().includes("ping")) {
|
||||
peer.send("pong");
|
||||
}
|
||||
},
|
||||
|
||||
close(peer, event) {
|
||||
console.log("[ws] close", peer, event);
|
||||
},
|
||||
|
||||
error(peer, error) {
|
||||
console.log("[ws] error", peer, error);
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user