Scroll to navigation

Dancer2::Plugin::WebSocket::Group(3) User Contributed Perl Documentation Dancer2::Plugin::WebSocket::Group(3)

NAME

Dancer2::Plugin::WebSocket::Group

VERSION

version 0.3.1

SYNOPSIS

    websocket_on_message sub {
        my( $conn, $message ) = @_;
        if ( $message eq 'tell to everybody' ) {
            $conn->to( '* ' )->send( "HEY, Y'ALL!" );
        }
    };

DESC

Those objects are generated via the "to" method of the Dancer2::Plugin::WebSocket::Connection objects, and allow to easily send to groups of connections.

In addition to any channels one might fancy creating, each connection also has a private channel that is associated to its numerical id, and a global channel "*" also exist to send messages to all connections.

Methods

Send the message to all connections of the group.

    $conn->to( 'players' )->send( "Hi!" );
    
Send the message to all connections of the group, except the original connection.

    websocket_on_message sub {
        my( $conn, $msg ) = @_;
        if ( $msg eq ='resign' ) {
            $conn->broadcast( "player ", $conn->idm " resigned" );
        }
    }
    

AUTHOR

Yanick Champoux <yanick@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2021, 2019, 2017 by Yanick Champoux.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

2021-05-31 perl v5.38.2