All notable changes to this project will be documented in this file.
Added create
identity fn to create typesafe messages and send them later. Available both on createPartyRpc
and
createPartyClient
.
const p = createPartyRpc<PartyResponses>();
const msg = p.create({
// typesafe message
type: "update",
id: websocket.id,
x: position.x,
y: position.y,
pointer: position.pointer,
country: attachment.country,
});
const { type, ...cursor } = msg;
websocket.serializeAttachment(cursor); // use it however you want
p.broadcast(room, msg, [websocket.id]); // send it later
Added options.debug
as string to only log what you need.
const client = createPartyClient<PartyEvents, PartyResponses>(socket, { debug: "sync" }); // will only log message with { type: "sync" }
Expose send
and broadcast
helper fns on the return of createPartyRpc().events()
so that you only need to export
this one
const p = createPartyRpc<PartyResponses>(); // no need to export p anymore !
export const niceParty = p.events({
// ...
});
// ...
niceParty.send(websocket, { ... });
Expose socket
on the return of createPartyClient()
, same reason, so that you only need to export this one
const socket = new PartySocket({ host: envConfig.PARTYKIT_HOST, room: "main" });
export const client = createPartyClient<PartyEvents, PartyResponses>(socket);
client.socket; // new !
Added the 3rd argument (withoutIds
) to createPartyRpc().broadcast()
to allow you to exclude some ids.
Renamed AnyResponse
type to AnyResponseMessage
to be more explicit.
Added useSocketEvent
to hook into base socket events (open
, close
, error
, message
).
const { useSocketEvent } = createPartyHooks(client);
useSocketEvent("open", () => {
console.log("socket opened");
});
Added unsubscribe
fn in client, to unsubscribe from all listeners.
const { unsubscribe } = createPartyHooks(client);
useEffect(() => {
// do stuff ...
return () => {
client.unsubscribe();
};
}, []);
Renamed usePartyEvent
to usePartyMessage
to be more explicit.
Add generic on send
helper fn, to allow overriding or forcing a specific type.
- const send = (ws: PartyKitConnection, message: BasePartyResponses | Responses) => ws.send(JSON.stringify(message));
+ const send = <T extends BasePartyResponses | Responses>(ws: PartyKitConnection, message: T) => ws.send(JSON.stringify(message));
Add broadcast
helper fn:
const broadcast = <Message extends BasePartyResponses | Responses>(room: PartyKitRoom, payload: Message) =>
room.broadcast(JSON.stringify(payload));
Swap order of generics of createPartyRpc
, make Context
optional.
- export const createPartyRpc = <Context, Responses>() => {}
+ export const createPartyRpc = <Responses, Context>() => {}
Add missing .d.ts files (for the multi-entrypoint) that were not included in the npm package.
Baseline Release 🎉