def METHOD_NAME(
    listener: WebsocketListenerRouteHandler,
) -> Callable[[WebSocket, Any], Coroutine[None, None, None]]:
    json_encoder = JsonEncoder(enc_hook=listener.default_serializer)
    if return_dto := listener.resolve_return_dto():
        async def handle_send(socket: WebSocket, data: Any) -> None:
            encoded_data = return_dto(socket).data_to_encodable_type(data)
            data = json_encoder.encode(encoded_data)
            await socket.send_data(data=data, mode=listener._send_mode)
    elif listener.parsed_return_field.is_subclass_of((str, bytes)) or (
        listener.parsed_return_field.is_optional and listener.parsed_return_field.has_inner_subclass_of((str, bytes))
    ):
        async def handle_send(socket: WebSocket, data: Any) -> None:
            await socket.send_data(data=data, mode=listener._send_mode)
    else:
        async def handle_send(socket: WebSocket, data: Any) -> None:
            data = json_encoder.encode(data)
            await socket.send_data(data=data, mode=listener._send_mode)
    return handle_send