1
1
import { createTRPCRouter , publicProcedure } from "../trpc" ;
2
2
import { z } from "zod" ;
3
- import { type PlayerJoinLeaveEvent as PlayerJoinLeftEvent } from "~/types/pusherEvents" ;
3
+ import {
4
+ type PlayerEmoteEvent ,
5
+ type PlayerJoinLeaveEvent as PlayerJoinLeftEvent ,
6
+ } from "~/types/pusherEvents" ;
4
7
import { pusherServer } from "~/utils/pusherServer" ;
5
8
import axios from "axios" ;
6
9
import { env } from "~/env" ;
@@ -16,7 +19,7 @@ export const socketsRouter = createTRPCRouter({
16
19
. input (
17
20
z . object ( {
18
21
username : z . string ( ) . min ( 1 ) ,
19
- gameId : z . string ( ) . min ( 1 ) ,
22
+ gameId : z . string ( ) . length ( 6 ) ,
20
23
} ) ,
21
24
)
22
25
. mutation ( ( opts ) => {
@@ -36,7 +39,7 @@ export const socketsRouter = createTRPCRouter({
36
39
. input (
37
40
z . object ( {
38
41
username : z . string ( ) . min ( 1 ) ,
39
- gameId : z . string ( ) . min ( 1 ) ,
42
+ gameId : z . string ( ) . length ( 6 ) ,
40
43
} ) ,
41
44
)
42
45
. mutation ( ( opts ) => {
@@ -47,6 +50,22 @@ export const socketsRouter = createTRPCRouter({
47
50
} ;
48
51
return pusherServer . trigger ( gameId , "player-left" , leftEvent ) ;
49
52
} ) ,
53
+ playerEmote : publicProcedure
54
+ . input (
55
+ z . object ( {
56
+ emote : z . string ( ) . min ( 1 ) ,
57
+ username : z . string ( ) . min ( 1 ) ,
58
+ gameId : z . string ( ) . length ( 6 ) ,
59
+ } ) ,
60
+ )
61
+ . mutation ( ( opts ) => {
62
+ const { emote, username, gameId } = opts . input ;
63
+ const emoteEvent : PlayerEmoteEvent = {
64
+ username,
65
+ emote,
66
+ } ;
67
+ return pusherServer . trigger ( gameId , "emote" , emoteEvent ) ;
68
+ } ) ,
50
69
getChannelInfo : publicProcedure
51
70
. input (
52
71
z . object ( {
0 commit comments