First you have to store websocket my $ws = $c->tx handle in your
'/ws/socket' path, and later use this same handle to $ws->send(...)
(this applies only when server runs in single thread mode)
On Friday, May 6, 2016 at 3:57:30 AM UTC+2, Lachlan Deck wrote:
>
> Hi there,
>
> I'm using Mojo Lite as a mock api server for an angular app.
>
> The api currently mostly only utilises a websocket for messages from the
> server to the client.
>
> Is it possible to send a message (after x seconds) via the websocket from
> a `post`?
>
> Say I have:
> use Mojolicious::Lite;
> ...
>
> websocket '/ws/socket' => sub {
> ...
> };
>
> post '/foo/bar' => {
> my $c = shift;
> ...
> $c->render(data => encode_json {...});
> Mojo::IOLoop->timer(2 => sub => {
> $c->send(json => {...})
> });
> };
>
> The message I get is `Can't call method "is_websocket" on an undefined
> value at /Users/ldeck/perl5/lib/perl5/Mojolicious/Controller.pm line 252.'
>
> Is there a way to do this?
>
> Thanks!
>
--
You received this message because you are subscribed to the Google Groups
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.