commit 474d0eda557d8d68904a01c8a27b5017676d08ad (patch)
parent a0f29931afdcfe3c83f28646645565bfde15142f
Author: Alex Karle <alex@karle.co>
Date: Sat, 2 May 2020 18:10:02 -0400
Euchre::Player: Add send method
This makes the websocket field transparent to callers.
Diffstat:
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/lib/Euchre/Dealer.pm b/lib/Euchre/Dealer.pm
@@ -121,7 +121,7 @@ sub handle_msg {
sub pong {
my ($p) = @_;
- $p->ws->send({ json => { msg_type => 'pong' } });
+ $p->send({ msg_type => 'pong' });
}
# player_name
@@ -540,7 +540,7 @@ sub broadcast_gamestate {
hand => $p->hand,
is_spectator => ($p->seat) ? 0 : 1,
};
- $p->ws->send({ json => $json });
+ $p->send($json);
}
}
@@ -663,7 +663,7 @@ sub chat {
msg_type => 'chat',
msg => "$p->name: $msg->{msg}"
};
- $player->ws->send({ json => $json });
+ $player->send($json);
}
}
diff --git a/lib/Euchre/Player.pm b/lib/Euchre/Player.pm
@@ -28,7 +28,13 @@ sub error {
errno => $errno,
msg => err_msg($errno),
};
- $self->ws->send({ json => $json});
+ $self->send($json);
+}
+
+# Send a JSON message
+sub send {
+ my ($self, $json) = @_;
+ $self->ws->send({ json => $json });
}
1;