tRPCttRPC
Powered by
nikoN
tRPC•9mo ago•
6 replies
niko

event emitter doesnt trigger subscription from webhook

I'm using subscription in nextjs using SSE, im trying to trigger subscription when webhook receives data, webhook is seprated page
api/webhook/route.ts
api/webhook/route.ts
and subscription is in
root.ts
root.ts
, I even tested subscription using little mock of
mutation
mutation
and
subsciption
subsciption
procedures and it was working fine,

here is the test which works ✅
 test: createTRPCRouter({
    emit: protectedProcedure
      .input(z.object({ message: z.string() }))
      .mutation(async ({ input }) => {
        mediaEvents.emit("test-event", {
          ...input,
        });
      }),
    on: protectedProcedure
      .subscription(async function* ({ signal }) {
        const eventKey = `test-event`;

        try {
          for await (const [data] of on(mediaEvents, eventKey, { signal })) {
            yield data;
          }
        } catch (error) {
          console.error(error);
        }
      }),
  }),
 test: createTRPCRouter({
    emit: protectedProcedure
      .input(z.object({ message: z.string() }))
      .mutation(async ({ input }) => {
        mediaEvents.emit("test-event", {
          ...input,
        });
      }),
    on: protectedProcedure
      .subscription(async function* ({ signal }) {
        const eventKey = `test-event`;

        try {
          for await (const [data] of on(mediaEvents, eventKey, { signal })) {
            yield data;
          }
        } catch (error) {
          console.error(error);
        }
      }),
  }),
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Cannot get subscription event to fire
molochMmoloch / ❓-help
3y ago
tRPC subscription : Access to socket ID from subscription
ChronicStoneCChronicStone / ❓-help
3y ago
subscription
Ahmed EidAAhmed Eid / ❓-help
4y ago