… | |
… | |
2785 | sub cf::client::send_drawinfo { |
2785 | sub cf::client::send_drawinfo { |
2786 | my ($self, $text, $flags) = @_; |
2786 | my ($self, $text, $flags) = @_; |
2787 | |
2787 | |
2788 | utf8::encode $text; |
2788 | utf8::encode $text; |
2789 | $self->send_packet (sprintf "drawinfo %d %s", $flags || cf::NDI_BLACK, $text); |
2789 | $self->send_packet (sprintf "drawinfo %d %s", $flags || cf::NDI_BLACK, $text); |
|
|
2790 | } |
|
|
2791 | |
|
|
2792 | =item $client->send_big_packet ($pkt) |
|
|
2793 | |
|
|
2794 | Like C<send_packet>, but tries to compress large packets, and fragments |
|
|
2795 | them as required. |
|
|
2796 | |
|
|
2797 | =cut |
|
|
2798 | |
|
|
2799 | our $MAXFRAGSIZE = cf::MAXSOCKBUF - 64; |
|
|
2800 | |
|
|
2801 | sub cf::client::send_big_packet { |
|
|
2802 | my ($self, $pkt) = @_; |
|
|
2803 | |
|
|
2804 | # try lzf for large packets |
|
|
2805 | $pkt = "lzf " . Compress::LZF::compress $pkt |
|
|
2806 | if 1024 <= length $pkt and $self->{can_lzf}; |
|
|
2807 | |
|
|
2808 | # split very large packets |
|
|
2809 | if ($MAXFRAGSIZE < length $pkt and $self->{can_lzf}) { |
|
|
2810 | $self->send_packet ("frag $_") for unpack "(a$MAXFRAGSIZE)*", $pkt; |
|
|
2811 | $pkt = "frag"; |
|
|
2812 | } |
|
|
2813 | |
|
|
2814 | $self->send_packet ($pkt); |
2790 | } |
2815 | } |
2791 | |
2816 | |
2792 | =item $client->send_msg ($channel, $msg, $color, [extra...]) |
2817 | =item $client->send_msg ($channel, $msg, $color, [extra...]) |
2793 | |
2818 | |
2794 | Send a drawinfo or msg packet to the client, formatting the msg for the |
2819 | Send a drawinfo or msg packet to the client, formatting the msg for the |
… | |
… | |
2946 | my $pkt = "msg " |
2971 | my $pkt = "msg " |
2947 | . $self->{json_coder}->encode ( |
2972 | . $self->{json_coder}->encode ( |
2948 | [$color & cf::NDI_CLIENT_MASK, $channel, $msg, @extra] |
2973 | [$color & cf::NDI_CLIENT_MASK, $channel, $msg, @extra] |
2949 | ); |
2974 | ); |
2950 | |
2975 | |
2951 | # try lzf for large packets |
|
|
2952 | $pkt = "lzf " . Compress::LZF::compress $pkt |
|
|
2953 | if 1024 <= length $pkt and $self->{can_lzf}; |
|
|
2954 | |
|
|
2955 | # split very large packets |
|
|
2956 | if (8192 < length $pkt and $self->{can_lzf}) { |
|
|
2957 | $self->send_packet ("frag $_") for unpack "(a8192)*", $pkt; |
|
|
2958 | $pkt = "frag"; |
|
|
2959 | } |
|
|
2960 | |
|
|
2961 | $self->send_packet ($pkt); |
2976 | $self->send_big_packet ($pkt); |
2962 | } |
2977 | } |
2963 | |
2978 | |
2964 | =item $client->ext_msg ($type, @msg) |
2979 | =item $client->ext_msg ($type, @msg) |
2965 | |
2980 | |
2966 | Sends an ext event to the client. |
2981 | Sends an ext event to the client. |
… | |
… | |
2969 | |
2984 | |
2970 | sub cf::client::ext_msg($$@) { |
2985 | sub cf::client::ext_msg($$@) { |
2971 | my ($self, $type, @msg) = @_; |
2986 | my ($self, $type, @msg) = @_; |
2972 | |
2987 | |
2973 | if ($self->extcmd == 2) { |
2988 | if ($self->extcmd == 2) { |
2974 | $self->send_packet ("ext " . $self->{json_coder}->encode ([$type, @msg])); |
2989 | $self->send_big_packet ("ext " . $self->{json_coder}->encode ([$type, @msg])); |
2975 | } elsif ($self->extcmd == 1) { # TODO: remove |
2990 | } elsif ($self->extcmd == 1) { # TODO: remove |
2976 | push @msg, msgtype => "event_$type"; |
2991 | push @msg, msgtype => "event_$type"; |
2977 | $self->send_packet ("ext " . $self->{json_coder}->encode ({@msg})); |
2992 | $self->send_big_packet ("ext " . $self->{json_coder}->encode ({@msg})); |
2978 | } |
2993 | } |
2979 | } |
2994 | } |
2980 | |
2995 | |
2981 | =item $client->ext_reply ($msgid, @msg) |
2996 | =item $client->ext_reply ($msgid, @msg) |
2982 | |
2997 | |
… | |
… | |
2986 | |
3001 | |
2987 | sub cf::client::ext_reply($$@) { |
3002 | sub cf::client::ext_reply($$@) { |
2988 | my ($self, $id, @msg) = @_; |
3003 | my ($self, $id, @msg) = @_; |
2989 | |
3004 | |
2990 | if ($self->extcmd == 2) { |
3005 | if ($self->extcmd == 2) { |
2991 | $self->send_packet ("ext " . $self->{json_coder}->encode (["reply-$id", @msg])); |
3006 | $self->send_big_packet ("ext " . $self->{json_coder}->encode (["reply-$id", @msg])); |
2992 | } elsif ($self->extcmd == 1) { |
3007 | } elsif ($self->extcmd == 1) { |
2993 | #TODO: version 1, remove |
3008 | #TODO: version 1, remove |
2994 | unshift @msg, msgtype => "reply", msgid => $id; |
3009 | unshift @msg, msgtype => "reply", msgid => $id; |
2995 | $self->send_packet ("ext " . $self->{json_coder}->encode ({@msg})); |
3010 | $self->send_big_packet ("ext " . $self->{json_coder}->encode ({@msg})); |
2996 | } |
3011 | } |
2997 | } |
3012 | } |
2998 | |
3013 | |
2999 | =item $success = $client->query ($flags, "text", \&cb) |
3014 | =item $success = $client->query ($flags, "text", \&cb) |
3000 | |
3015 | |